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

String parameter format #4

Closed
TomerRZN opened this issue Jul 13, 2020 · 4 comments
Closed

String parameter format #4

TomerRZN opened this issue Jul 13, 2020 · 4 comments

Comments

@TomerRZN
Copy link

Did i miss a way to create an OpenApiParam and describing its format (or any other schema property)?

@GabrielCappelli
Copy link
Owner

If you pass an object that's a Dataclass or contains a Marshmallow Schema in attribute __marshmallow__ it'll be able to identify it and generate the schema.

from dataclasses import dataclass
from openapi_specgen import OpenApiParam
@dataclass
class Foo():
    bar: str

param = OpenApiParam('test_param', 'query', Foo)
param.as_dict() 

# Generated output for this OpenApiParam 
#{'required': True, 'name': 'test_param', 'in': 'query', 'schema': {'$ref': '#/components/schemas/Foo', 'title': 'Test_Param'}}

@TomerRZN
Copy link
Author

TomerRZN commented Jul 14, 2020

I do understand that this is how you generate schema for various objects, however this is not the case i was talking about.
I want to describe a param's properties in the case it isn't an object.
Few examples (In yaml since i took them from website):

A string parameter with a format of uuid
- in: header name: X-Request-ID schema: type: string **format: uuid** required: true

An integer parameter whose value is an enum:
- in: cookie name: debug schema: type: integer **enum: [0, 1]**

An integer parameter with minimum value:
- in: query name: offset schema: type: integer minimum: 0 default: 0 required: false

@GabrielCappelli
Copy link
Owner

Oh, sorry, I misunderstood.

Currently format is supported only by type. Meaning specific types have specific formats (date and datetime).

We can add a optional parameter format, if specified it'll be set as the format in the schema for that param.

Does that work for you ?

@GabrielCappelli
Copy link
Owner

Expected way to do this in 1.0.0 is using a custom type and a custom resolver.

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