I am taking the reverse road most usually take by generating openapi3 documentation from a minimal http framework on top of chi, the start was pretty fast and I can generate everything I need for the request path arguments but I am stuck trying to generate a schema for the requestBody of an operation, my best attempt so far is:
type Pet struct {
Id string `json:"id"`
Name string `json:"name"`
}
gen := openapi3gen.NewGenerator()
// bodyField points to `Pet` reflected type
bodySchema, err := gen.GenerateSchemaRef(bodyField.Type)
// error is checked but I removed it for clarity
body := openapi3.NewRequestBody()
body.Content = openapi3.NewContentWithJSONSchema(bodySchema.Value)
bodyRef := &openapi3.RequestBodyRef{
Value: body,
}
op.RequestBody = bodyRef
swagger.AddOperation(pattern, method, op)
Aside from being really verbose (there may be faster way to do things but that's the best I found for now) this works but generates:
{
"content": {
"application/json": {
"schema": {
"properties": {
"id": {
"$ref": "string"
},
"name": {
"$ref": "string"
}
},
"type": "object"
}
}
}
}
this cause the viewers to try and request <my-domain>/string and i am not sure what I missed, from what I understand internal references should start with "#" but I see no way of influencing what ref are generated and I feel my lack of familiarity with openapi3 does not help xD
Any help or pointer in the right direction will be greatly appreciated :)
I am taking the reverse road most usually take by generating openapi3 documentation from a minimal http framework on top of chi, the start was pretty fast and I can generate everything I need for the request path arguments but I am stuck trying to generate a schema for the
requestBodyof an operation, my best attempt so far is:Aside from being really verbose (there may be faster way to do things but that's the best I found for now) this works but generates:
{ "content": { "application/json": { "schema": { "properties": { "id": { "$ref": "string" }, "name": { "$ref": "string" } }, "type": "object" } } } }this cause the viewers to try and request
<my-domain>/stringand i am not sure what I missed, from what I understand internal references should start with "#" but I see no way of influencing what ref are generated and I feel my lack of familiarity with openapi3 does not help xDAny help or pointer in the right direction will be greatly appreciated :)