Skip to content

Commit

Permalink
cli: fix missing scalar alias
Browse files Browse the repository at this point in the history
  • Loading branch information
hgiasac committed Dec 12, 2024
1 parent 849466c commit 67ce0d2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
14 changes: 14 additions & 0 deletions ndc-http-schema/openapi/internal/oas2.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,16 @@ func (oc *OAS2Builder) convertComponentSchemas(schemaItem orderedmap.Pair[string
typeSchema := typeValue.Schema()

oc.Logger.Debug("component schema", slog.String("name", typeKey))
if _, ok := oc.schema.ObjectTypes[typeKey]; ok {
return nil
}
if _, ok := oc.schema.ScalarTypes[typeKey]; ok {
return nil
}
if typeSchema == nil {
return nil
}

typeEncoder, schemaResult, err := newOAS2SchemaBuilder(oc, "", rest.InBody).getSchemaType(typeSchema, []string{typeKey})

var typeName string
Expand All @@ -229,6 +236,13 @@ func (oc *OAS2Builder) convertComponentSchemas(schemaItem orderedmap.Pair[string
}
}

// If the result type is a scalar, the builder returns the raw scalar name (String, Int).
// We should check and add the alias type to scalar objects
pascalTypeName := utils.ToPascalCase(typeKey)
if scalarType, ok := oc.schema.ScalarTypes[typeName]; ok && pascalTypeName != typeName {
oc.schema.ScalarTypes[pascalTypeName] = scalarType
}

cacheKey := "#/definitions/" + typeKey
// treat no-property objects as a Arbitrary JSON scalar
if typeEncoder == nil || typeName == string(rest.ScalarJSON) {
Expand Down
11 changes: 11 additions & 0 deletions ndc-http-schema/openapi/internal/oas3.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,10 @@ func (oc *OAS3Builder) convertComponentSchemas(schemaItem orderedmap.Pair[string
if _, ok := oc.schema.ObjectTypes[typeKey]; ok {
return nil
}
if _, ok := oc.schema.ScalarTypes[typeKey]; ok {
return nil
}

typeEncoder, schemaResult, err := newOAS3SchemaBuilder(oc, "", rest.InBody, false).
getSchemaType(typeSchema, []string{typeKey})
if err != nil {
Expand All @@ -282,6 +286,13 @@ func (oc *OAS3Builder) convertComponentSchemas(schemaItem orderedmap.Pair[string
}
}

// If the result type is a scalar, the builder returns the raw scalar name (String, Int).
// We should check and add the alias type to scalar objects
pascalTypeName := utils.ToPascalCase(typeKey)
if scalarType, ok := oc.schema.ScalarTypes[typeName]; ok && pascalTypeName != typeName {
oc.schema.ScalarTypes[pascalTypeName] = scalarType
}

cacheKey := "#/components/schemas/" + typeKey
// treat no-property objects as a Arbitrary JSON scalar
if typeEncoder == nil || typeName == string(rest.ScalarJSON) {
Expand Down

0 comments on commit 67ce0d2

Please sign in to comment.