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

Is there a way to get a constant/static value for a field? #144

Closed
beaugunderson opened this issue Jun 14, 2018 · 1 comment
Closed

Is there a way to get a constant/static value for a field? #144

beaugunderson opened this issue Jun 14, 2018 · 1 comment

Comments

@beaugunderson
Copy link
Contributor

Here's my use case:

I'd like to define a field on a Django model like result_type = 'staff', expose it in a DRF serializer by including it in fields = (..., 'result_type'), and have the static value 'staff' exposed in the schema.

I want this because we use the schema to generate flowtypes for our project, and we sometimes need to do type refinements between models, and a static value would help tremendously here.

@axnsan12
Copy link
Owner

Seems to be an open issue: OAI/OpenAPI-Specification#1313. So not currently possible, and most likely never will be possible in OpenAPI 2.

Best you could do would probably be adding a default to your serializer field:

result_type = serializers.ModelField(model_field='result_type', default=ModelClass.result_type, help_text='Always "' + ModelClass.result_type + '"')

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