Skip to content

feat(net/goai): add configurable type mapping for oai type#4761

Closed
StrangeYear wants to merge 1 commit into
gogf:masterfrom
StrangeYear:goai-type-mapping
Closed

feat(net/goai): add configurable type mapping for oai type#4761
StrangeYear wants to merge 1 commit into
gogf:masterfrom
StrangeYear:goai-type-mapping

Conversation

@StrangeYear

Copy link
Copy Markdown

Summary

This PR adds a configurable type mapping mechanism in goai so specific Go types can be generated as custom OpenAPI schema types.
This solves cases like carbon.Carbon, which should be emitted as string instead of object.

Changes

  • added Config.TypeMapping map[string]string in net/goai
  • applied type mapping in golangTypeToOAIType before default type inference
  • supported both mapping key formats:
    • short type name, e.g. carbon.Carbon
    • full type id, e.g. github.com/golang-module/carbon/v2.Carbon
  • added unit test Test_TypeMapping to verify mapped struct type is emitted as string

Usage Example

oai := goai.New()
oai.Config.TypeMapping = map[string]string{
	"carbon.Carbon":                              goai.TypeString,
	"github.com/golang-module/carbon/v2.Carbon": goai.TypeString,
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant