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

required params in schema #23

Open
SergeyCYI opened this issue Oct 10, 2023 · 3 comments
Open

required params in schema #23

SergeyCYI opened this issue Oct 10, 2023 · 3 comments

Comments

@SergeyCYI
Copy link

SergeyCYI commented Oct 10, 2023

Could you please tell me how I can add a list of mandatory parameters to the schema?
Example:
components:
schemas:
Request:
type: object
properties:
id:
type: integer
required: [
id,
]

@vearutop
Copy link
Member

Hello, please try adding required:"true" tag to the fields that should be required. E.g.

type My struct {
 ID int `json:"id" required:"true"`
}

@SergeyCYI
Copy link
Author

Hello, please try adding required:"true" tag to the fields that should be required. E.g.

type My struct {
 ID int `json:"id" required:"true"`
}

hint, how to realize this scheme:

channels:
  /:
    publish:
      description: Send messages to the API
      operationId: processReceivedMessage
      message:
        oneOf:
          - $ref: '#/components/messages/ping'
          - $ref: '#/components/messages/subscribe'
          - $ref: '#/components/messages/unsubscribe'
 

specifically "message: oneOf:"

@vearutop
Copy link
Member

Hi, if you need to declare oneOf, you can implement jsonschema.OneOfExposer on your message type.

type MyMessage struct{}

func (MyMessage ) JSONSchemaOneOf() []interface{} {
	return []interface{}{
		Ping{}, Subscribe{}, Unsubscribe{}
	}
}

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

No branches or pull requests

2 participants