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
4 changes: 3 additions & 1 deletion internal/test/issues/issue-958/issue.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 12 additions & 9 deletions pkg/codegen/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,15 +278,25 @@ func (o *OperationDefinition) GetResponseTypeDefinitions() ([]ResponseTypeDefini
sortedResponsesKeys := SortedResponsesKeys(responses)
for _, responseName := range sortedResponsesKeys {
responseRef := responses[responseName]

refParts := strings.Split(responseRef.Ref, "#")
// Checking to see if reference belongs to external doc so child content can be adjusted.
_, isExternalImport := importMapping[refParts[0]]
// We can only generate a type if we have a value:
if responseRef.Value != nil {
sortedContentKeys := SortedContentKeys(responseRef.Value.Content)
for _, contentTypeName := range sortedContentKeys {
contentType := responseRef.Value.Content[contentTypeName]
// We can only generate a type if we have a schema:
if contentType.Schema != nil {
responseSchema, err := GenerateGoSchema(contentType.Schema, []string{responseName})
// Create a copy as to not disturb original.
schemaCopy := *contentType.Schema
// When an external reference is provided, adjust the ref to contain full path so imports can be attached.
if isExternalImport && IsGoTypeReference(schemaCopy.Ref) {
schemaParts := strings.Split(schemaCopy.Ref, "#")
refDef := schemaParts[len(schemaParts)-1]
schemaCopy.Ref = fmt.Sprintf("%s#%s", refParts[0], refDef)
}
responseSchema, err := GenerateGoSchema(&schemaCopy, []string{responseName})
if err != nil {
return nil, fmt.Errorf("Unable to determine Go type for %s.%s: %w", o.OperationId, contentTypeName, err)
}
Expand All @@ -313,13 +323,6 @@ func (o *OperationDefinition) GetResponseTypeDefinitions() ([]ResponseTypeDefini
ResponseName: responseName,
ContentTypeName: contentTypeName,
}
if IsGoTypeReference(contentType.Schema.Ref) {
refType, err := RefPathToGoType(contentType.Schema.Ref)
if err != nil {
return nil, fmt.Errorf("error dereferencing response Ref: %w", err)
}
td.Schema.RefType = refType
}
tds = append(tds, td)
}
}
Expand Down