Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

openapi3gen: Fix issue with separate component generated for time.Time #1052

Merged
merged 2 commits into from
Feb 10, 2025

Conversation

d1vbyz3r0
Copy link
Contributor

openapi3gen generates separate schema component for time.Time properies, when ExportComponentSchemas opt provided.
Here is a small example:

type Some struct {
	Name      string
	CreatedAt time.Time
}

func main() {
	schemas := make(openapi3.Schemas)
	g := openapi3gen.NewGenerator(
		openapi3gen.UseAllExportedFields(),
		openapi3gen.CreateComponentSchemas(openapi3gen.ExportComponentSchemasOptions{
			ExportComponentSchemas: true,
		}),
	)

	ref, err := g.NewSchemaRefForValue(&Some{}, schemas)
	if err != nil {
		panic(err)
	}

	schema, _ := json.MarshalIndent(ref, "", "  ")
	fmt.Println(string(schema))
}

Expected output is:

{
  "properties": {
    "CreatedAt": {
      "format": "date-time",
      "type": "string"
    },
    "Name": {
      "type": "string"
    }
  },
  "type": "object"
}

But for now generator produces following:

{
  "properties": {
    "CreatedAt": {
      "$ref": "#/components/schemas/Time"
    },
    "Name": {
      "type": "string"
    }
  },
  "type": "object"
}

…e fields, when ExportComponentSchemas opt provided
@fenollp
Copy link
Collaborator

fenollp commented Feb 10, 2025

Please add your example as a test and we should be good to go.

@fenollp fenollp merged commit 050a930 into getkin:master Feb 10, 2025
5 checks passed
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.

2 participants