Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion pkg/codegen/codegen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,11 @@ func TestExampleOpenAPICodeGeneration(t *testing.T) {
},
}

loader := openapi3.NewLoader()
loader.IsExternalRefsAllowed = true

// Get a spec from the test definition in this file:
swagger, err := openapi3.NewLoader().LoadFromData([]byte(testOpenAPIDefinition))
swagger, err := loader.LoadFromData([]byte(testOpenAPIDefinition))
assert.NoError(t, err)

// Run our code generation:
Expand Down
10 changes: 8 additions & 2 deletions pkg/codegen/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ func TestFilterOperationsByTag(t *testing.T) {
},
}

loader := openapi3.NewLoader()
loader.IsExternalRefsAllowed = true

// Get a spec from the test definition in this file:
swagger, err := openapi3.NewLoader().LoadFromData([]byte(testOpenAPIDefinition))
swagger, err := loader.LoadFromData([]byte(testOpenAPIDefinition))
assert.NoError(t, err)

// Run our code generation:
Expand All @@ -49,8 +52,11 @@ func TestFilterOperationsByTag(t *testing.T) {
},
}

loader := openapi3.NewLoader()
loader.IsExternalRefsAllowed = true

// Get a spec from the test definition in this file:
swagger, err := openapi3.NewLoader().LoadFromData([]byte(testOpenAPIDefinition))
swagger, err := loader.LoadFromData([]byte(testOpenAPIDefinition))
assert.NoError(t, err)

// Run our code generation:
Expand Down
4 changes: 2 additions & 2 deletions pkg/codegen/merge_schemas.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ func valueWithPropagatedRef(ref *openapi3.SchemaRef) (openapi3.Schema, error) {
}

pathParts := strings.Split(ref.Ref, "#")
if len(pathParts) != 2 {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This appears to be an artificial limitation for pathParts to have exactly 2 parts.

if len(pathParts) < 1 || len(pathParts) > 2 {
return openapi3.Schema{}, fmt.Errorf("unsupported reference: %s", ref.Ref)
}
remoteComponent, _ := pathParts[0], pathParts[1]
remoteComponent := pathParts[0]

// remote ref
schema := *ref.Value
Expand Down
15 changes: 15 additions & 0 deletions pkg/codegen/test_schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"title": "node",
"type": "object",
"description": "Represents a node",
"properties": {
"id": {
"type": "string",
"format": "uri-reference"
},
"type": {
"type": "string",
"pattern": "^[A-Z][a-zA-Z0-9]*$"
}
}
}
28 changes: 28 additions & 0 deletions pkg/codegen/test_spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,25 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/Error'
/user:
get:
tags:
- mergeAllOf
summary: Merges allOf ref-ing a JSON schema
operationId: getUser
responses:
200:
description: Success
content:
application/json:
schema:
$ref: '#/components/schemas/User'
default:
description: Error
content:
application/json:
schema:
$ref: '#/components/schemas/Error'

components:
schemas:
Expand Down Expand Up @@ -177,3 +196,12 @@ components:
- na
- single
- double
User:
allOf:
- $ref: ./test_schema.json
- type: object
additionalProperties: false
properties:
name:
type: string
description: User name