Skip to content

Commit

Permalink
test: change test setschema to example
Browse files Browse the repository at this point in the history
  • Loading branch information
blackhun11 committed Mar 30, 2024
1 parent 409186a commit e40d39d
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions openapi3gen/openapi3gen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -602,20 +602,31 @@ func (_ *ID) SetSchema(schema *openapi3.Schema) {
schema.Type = &openapi3.Types{"string"} // Assuming this matches your custom implementation
schema.Format = "uuid"
}
func TestNewSchemaRefForValueWithSetSchemar(t *testing.T) {

func ExampleID_SetSchema() {
schemas := make(openapi3.Schemas)
instance := &T{
ID: ID{},
}

// Generate the schema for the instance
schemaRef, err := openapi3gen.NewSchemaRefForValue(instance, schemas)
require.NoError(t, err, "should not error when generating schema ref")

// Optional: Marshal and inspect the schemas and schemaRef if needed for further verification
_, err = json.MarshalIndent(schemas, "", " ")
require.NoError(t, err, "error marshaling schemas")

_, err = json.MarshalIndent(schemaRef, "", " ")
require.NoError(t, err, "error marshaling schemaRef")
if err != nil {
panic(err)
}
data, err := json.MarshalIndent(schemaRef, "", " ")
if err != nil {
panic(err)
}
fmt.Printf("schemaRef: %s\n", data)
// Output:
// schemaRef: {
// "properties": {
// "id": {
// "format": "uuid",
// "type": "string"
// }
// },
// "type": "object"
// }
}

0 comments on commit e40d39d

Please sign in to comment.