Skip to content

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