Replies: 1 comment 1 reply
-
|
Hi, I think the easiest way would be to use property interceptor and throw Please check the following example (requires latest type SomeStruct struct {
ActivityID int `json:"activityID" db:"activity_id" required:"true"` // activity_id
ProjectID int `json:"projectID" db:"project_id" required:"true"` // project_id
Name string `json:"name" db:"name" required:"true"` // name
Description string `json:"description" db:"description" required:"true"` // description
IsProductive bool `json:"isProductive" db:"is_productive" required:"true"` // is_productive
TimeEntries *[]TimeEntry `json:"timeEntries" db:"time_entries" openapi-go:"ignore"` // O2M
// xo fields
_exists, _deleted bool
}
reflector := openapi3.Reflector{Spec: &openapi3.Spec{}}
reflector.DefaultOptions = append(reflector.DefaultOptions, jsonschema.InterceptProp(func(params jsonschema.InterceptPropParams) error {
if params.Field.Tag.Get("openapi-go") == "ignore" {
println("IGNORING", params.Name)
return jsonschema.ErrSkipProperty
}
return nil
}))
st := SomeStruct{}
dummyOp := openapi3.Operation{}
handleError(reflector.SetJSONResponse(&dummyOp, st, http.StatusTeapot))
handleError(reflector.Spec.AddOperation(http.MethodGet, "/dummy-op", dummyOp))openapi: ""
info:
title: ""
version: ""
paths:
/dummy-op:
get:
responses:
"418":
content:
application/json:
schema:
$ref: '#/components/schemas/SomeStruct'
description: I'm a teapot
components:
schemas:
SomeStruct:
properties:
activityID:
type: integer
description:
type: string
isProductive:
type: boolean
name:
type: string
projectID:
type: integer
required:
- activityID
- projectID
- name
- description
- isProductive
type: object |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Is there a way to ignore certain fields for schema generation? I tried to use a new struct created with reflection based on my own
openapi-go:"ignore"tag, but that gives trouble when generating schemas on a struct created with reflection, it generates an anonymous schema:is :
expected output:
So I guess the question is either:
InterceptDefNameis not called in this caseswaggest/reflBeta Was this translation helpful? Give feedback.
All reactions