Skip to content

Commit

Permalink
fix missing Boolean scalar
Browse files Browse the repository at this point in the history
  • Loading branch information
hgiasac committed Nov 14, 2024
1 parent faa3a32 commit 45bf57e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ndc-http-schema/openapi/internal/oas2_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,9 @@ func (oc *oas2OperationBuilder) convertResponse(responses *v2.Responses, apiPath
// return nullable boolean type if the response content is null
if resp == nil || resp.Schema == nil {
scalarName := string(rest.ScalarBoolean)
if _, ok := oc.builder.schema.ScalarTypes[scalarName]; !ok {
oc.builder.schema.ScalarTypes[scalarName] = *defaultScalarTypes[rest.ScalarBoolean]
}

return schema.NewNullableNamedType(scalarName), nil
}
Expand Down
4 changes: 4 additions & 0 deletions ndc-http-schema/openapi/internal/oas3_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,10 @@ func (oc *oas3OperationBuilder) convertResponse(responses *v3.Responses, apiPath
// return nullable boolean type if the response content is null
if resp == nil || resp.Content == nil {
scalarName := string(rest.ScalarBoolean)
if _, ok := oc.builder.schema.ScalarTypes[scalarName]; !ok {
oc.builder.schema.ScalarTypes[scalarName] = *defaultScalarTypes[rest.ScalarBoolean]
}

return schema.NewNullableNamedType(scalarName), &rest.Response{
ContentType: rest.ContentTypeJSON,
}, nil
Expand Down
7 changes: 7 additions & 0 deletions ndc-http-schema/openapi/internal/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func getScalarFromType(sm *rest.NDCHttpSchema, names []string, format string, en
if _, ok := sm.ScalarTypes[scalarName]; !ok {
sm.ScalarTypes[scalarName] = *scalarType
}

return scalarName, nullable
}

Expand Down Expand Up @@ -251,6 +252,7 @@ func getMethodAlias(inputs ...map[string]string) map[string]string {
methodAlias[k] = alias
}
}

return methodAlias
}

Expand All @@ -262,6 +264,7 @@ func convertSecurities(securities []*base.SecurityRequirement) rest.AuthSecuriti
results = append(results, s)
}
}

return results
}

Expand All @@ -277,6 +280,7 @@ func convertSecurity(security *base.SecurityRequirement) rest.AuthSecurity {
}
results[s.Key()] = v
}

return results
}

Expand All @@ -287,6 +291,7 @@ func isPrimitiveScalar(names []string) bool {
return false
}
}

return true
}

Expand All @@ -299,6 +304,7 @@ func getNamedType(typeSchema schema.TypeEncoder, recursive bool, defaultValue st
if !recursive {
return defaultValue
}

return getNamedType(ty.ElementType.Interface(), recursive, defaultValue)
case *schema.NamedType:
return ty.Name
Expand All @@ -309,6 +315,7 @@ func getNamedType(typeSchema schema.TypeEncoder, recursive bool, defaultValue st

func isNullableType(input schema.TypeEncoder) bool {
_, ok := input.(*schema.NullableType)

return ok
}

Expand Down

0 comments on commit 45bf57e

Please sign in to comment.