add some comments, redesign style of enums in simple and long view, fix tests to these new changes
This commit is contained in:
		@@ -110,7 +110,7 @@ Takes dictionary as argument with keys:
 | 
				
			|||||||
        {{- if eq 1 (len $.FieldPath) -}}
 | 
					        {{- if eq 1 (len $.FieldPath) -}}
 | 
				
			||||||
            {{- /* TODO: The original explain would say RESOURCE instead of FIELD here under some circumstances */ -}}
 | 
					            {{- /* TODO: The original explain would say RESOURCE instead of FIELD here under some circumstances */ -}}
 | 
				
			||||||
            FIELD: {{first $.FieldPath}} <{{ template "typeGuess" (dict "schema" $subschema "Document" $.Document) }}>{{"\n"}}
 | 
					            FIELD: {{first $.FieldPath}} <{{ template "typeGuess" (dict "schema" $subschema "Document" $.Document) }}>{{"\n"}}
 | 
				
			||||||
            {{- template "extractEnum" (dict "schema" $subschema "Document" $.Document "longFormView" false "limit" 3) -}}{{"\n"}}
 | 
					            {{- template "extractEnum" (dict "schema" $subschema "Document" $.Document "isLongView" true "limit" -1) -}}{{"\n"}}
 | 
				
			||||||
            {{- "\n" -}}
 | 
					            {{- "\n" -}}
 | 
				
			||||||
        {{- end -}}
 | 
					        {{- end -}}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -205,7 +205,7 @@ Takes dictionary as argument with keys:
 | 
				
			|||||||
    {{- $fieldSchema := index $.schema.properties $.name -}}
 | 
					    {{- $fieldSchema := index $.schema.properties $.name -}}
 | 
				
			||||||
    {{- $.name | indent $indentAmount -}}{{"\t"}}<{{ template "typeGuess" (dict "schema" $fieldSchema "Document" $.Document) }}>
 | 
					    {{- $.name | indent $indentAmount -}}{{"\t"}}<{{ template "typeGuess" (dict "schema" $fieldSchema "Document" $.Document) }}>
 | 
				
			||||||
    {{- if contains $.schema.required $.name}} -required-{{- end -}}
 | 
					    {{- if contains $.schema.required $.name}} -required-{{- end -}}
 | 
				
			||||||
    {{- template "extractEnum" (dict "schema" $fieldSchema "Document" $.Document "longFormView" true "limit" -1 "indentAmount" $indentAmount) -}}
 | 
					    {{- template "extractEnum" (dict "schema" $fieldSchema "Document" $.Document "isLongView" false "limit" 4 "indentAmount" $indentAmount) -}}
 | 
				
			||||||
    {{- "\n" -}}
 | 
					    {{- "\n" -}}
 | 
				
			||||||
    {{- if not $.short -}}
 | 
					    {{- if not $.short -}}
 | 
				
			||||||
        {{- or $fieldSchema.description "<no description>" | wrap (sub 78 $indentAmount) | indent (add $indentAmount 2) -}}{{- "\n" -}}
 | 
					        {{- or $fieldSchema.description "<no description>" | wrap (sub 78 $indentAmount) | indent (add $indentAmount 2) -}}{{- "\n" -}}
 | 
				
			||||||
@@ -295,7 +295,7 @@ Takes dictionary as argument with keys:
 | 
				
			|||||||
Takes dictionary as argument with keys:
 | 
					Takes dictionary as argument with keys:
 | 
				
			||||||
    schema: openapiv3 JSON schema
 | 
					    schema: openapiv3 JSON schema
 | 
				
			||||||
    Document: openapi document
 | 
					    Document: openapi document
 | 
				
			||||||
    longFormView: (boolean) prints the enums in extended long form view or not
 | 
					    isLongView: (boolean) Simple view: long list of all fields. Long view: all details of one field
 | 
				
			||||||
    limit: (int) truncate the amount of enums that can be printed in simple view, -1 means all items
 | 
					    limit: (int) truncate the amount of enums that can be printed in simple view, -1 means all items
 | 
				
			||||||
    indentAmount: intent of the beginning enum line in longform view
 | 
					    indentAmount: intent of the beginning enum line in longform view
 | 
				
			||||||
*/ -}}
 | 
					*/ -}}
 | 
				
			||||||
@@ -304,7 +304,7 @@ Takes dictionary as argument with keys:
 | 
				
			|||||||
        {{- if .enum -}}
 | 
					        {{- if .enum -}}
 | 
				
			||||||
            {{- $enumLen := len .enum -}}
 | 
					            {{- $enumLen := len .enum -}}
 | 
				
			||||||
            {{- $limit := or $.limit -1 -}}
 | 
					            {{- $limit := or $.limit -1 -}}
 | 
				
			||||||
            {{- if $.longFormView -}}
 | 
					            {{- if eq $.isLongView false -}}
 | 
				
			||||||
                {{- "\n" -}}
 | 
					                {{- "\n" -}}
 | 
				
			||||||
                {{- "" | indent $.indentAmount -}}
 | 
					                {{- "" | indent $.indentAmount -}}
 | 
				
			||||||
                {{- "enum: " -}}
 | 
					                {{- "enum: " -}}
 | 
				
			||||||
@@ -312,14 +312,22 @@ Takes dictionary as argument with keys:
 | 
				
			|||||||
                {{- "ENUM:" -}}
 | 
					                {{- "ENUM:" -}}
 | 
				
			||||||
            {{- end -}}
 | 
					            {{- end -}}
 | 
				
			||||||
            {{- range $index, $element := .enum -}}
 | 
					            {{- range $index, $element := .enum -}}
 | 
				
			||||||
 | 
					                {{- /* Prints , ....  and return the range when it goes over the limit */ -}}
 | 
				
			||||||
                {{- if and (gt $limit -1) (ge $index $limit) -}}
 | 
					                {{- if and (gt $limit -1) (ge $index $limit) -}}
 | 
				
			||||||
                    {{- /* Prints ,..  and return the range when it goes over the limit */ -}}
 | 
					                    {{- ", ...." -}}
 | 
				
			||||||
                    {{- ",.." -}}
 | 
					 | 
				
			||||||
                    {{- break -}}
 | 
					                    {{- break -}}
 | 
				
			||||||
                {{- end -}}
 | 
					                {{- end -}}
 | 
				
			||||||
                {{- /* Use to reflect "" when we see empty string */ -}}
 | 
					                {{- /* Use to reflect "" when we see empty string */ -}}
 | 
				
			||||||
                {{- $elementType := printf "%T" $element -}}
 | 
					                {{- $elementType := printf "%T" $element -}}
 | 
				
			||||||
                {{- if gt $index 0 -}} {{- ", " -}} {{- end -}}
 | 
					                {{- /* Print out either `, ` or `\n    ` based of the view */ -}}
 | 
				
			||||||
 | 
					                {{- /* Simple view */ -}}
 | 
				
			||||||
 | 
					                {{- if and (gt $index 0) (eq $.isLongView false) -}}
 | 
				
			||||||
 | 
					                    {{- ", " -}}
 | 
				
			||||||
 | 
					                {{- /* Long view */ -}}
 | 
				
			||||||
 | 
					                {{- else if eq $.isLongView true -}}
 | 
				
			||||||
 | 
					                    {{- "\n" -}}{{- "" | indent 4 -}}
 | 
				
			||||||
 | 
					                {{- end -}}
 | 
				
			||||||
 | 
					                {{- /* Convert empty string to `""` for more clarification */ -}}
 | 
				
			||||||
                {{- if and (eq "string" $elementType) (eq $element "") -}}
 | 
					                {{- if and (eq "string" $elementType) (eq $element "") -}}
 | 
				
			||||||
                    {{- `""` -}}
 | 
					                    {{- `""` -}}
 | 
				
			||||||
                {{- else -}}
 | 
					                {{- else -}}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -673,10 +673,10 @@ func TestPlaintext(t *testing.T) {
 | 
				
			|||||||
					"description": "a description that should not be printed",
 | 
										"description": "a description that should not be printed",
 | 
				
			||||||
					"enum":        []any{0, 1, 2, 3},
 | 
										"enum":        []any{0, 1, 2, 3},
 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
				"longFormView": false,
 | 
									"isLongView": true,
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			Checks: []check{
 | 
								Checks: []check{
 | 
				
			||||||
				checkEquals("ENUM: 0, 1, 2, 3"),
 | 
									checkEquals("ENUM:\n    0\n    1\n    2\n    3"),
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
@@ -689,7 +689,7 @@ func TestPlaintext(t *testing.T) {
 | 
				
			|||||||
					"description": "a description that should not be printed",
 | 
										"description": "a description that should not be printed",
 | 
				
			||||||
					"enum":        []any{0, 1, 2, 3},
 | 
										"enum":        []any{0, 1, 2, 3},
 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
				"longFormView": true,
 | 
									"isLongView":   false,
 | 
				
			||||||
				"indentAmount": 2,
 | 
									"indentAmount": 2,
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			Checks: []check{
 | 
								Checks: []check{
 | 
				
			||||||
@@ -706,12 +706,12 @@ func TestPlaintext(t *testing.T) {
 | 
				
			|||||||
					"description": "a description that should not be printed",
 | 
										"description": "a description that should not be printed",
 | 
				
			||||||
					"enum":        []any{0, 1, 2, 3},
 | 
										"enum":        []any{0, 1, 2, 3},
 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
				"longFormView": true,
 | 
									"isLongView":   false,
 | 
				
			||||||
				"limit":        2,
 | 
									"limit":        2,
 | 
				
			||||||
				"indentAmount": 2,
 | 
									"indentAmount": 2,
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			Checks: []check{
 | 
								Checks: []check{
 | 
				
			||||||
				checkEquals("\n  enum: 0, 1,.."),
 | 
									checkEquals("\n  enum: 0, 1, ...."),
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
@@ -724,12 +724,12 @@ func TestPlaintext(t *testing.T) {
 | 
				
			|||||||
					"description": "a description that should not be printed",
 | 
										"description": "a description that should not be printed",
 | 
				
			||||||
					"enum":        []any{0, 1, 2, 3},
 | 
										"enum":        []any{0, 1, 2, 3},
 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
				"longFormView": false,
 | 
									"isLongView":   true,
 | 
				
			||||||
				"limit":        2,
 | 
									"limit":        2,
 | 
				
			||||||
				"indentAmount": 2,
 | 
									"indentAmount": 2,
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			Checks: []check{
 | 
								Checks: []check{
 | 
				
			||||||
				checkEquals("ENUM: 0, 1,.."),
 | 
									checkEquals("ENUM:\n    0\n    1, ...."),
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
@@ -742,10 +742,10 @@ func TestPlaintext(t *testing.T) {
 | 
				
			|||||||
					"description": "a description that should not be printed",
 | 
										"description": "a description that should not be printed",
 | 
				
			||||||
					"enum":        []any{"Block", "File", ""},
 | 
										"enum":        []any{"Block", "File", ""},
 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
				"longFormView": false,
 | 
									"isLongView": true,
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			Checks: []check{
 | 
								Checks: []check{
 | 
				
			||||||
				checkEquals("ENUM: Block, File, \"\""),
 | 
									checkEquals("ENUM:\n    Block\n    File\n    \"\""),
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user