Skip to content

Define valid HTTP method depending on openapi version #374

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

Merged
merged 1 commit into from
Feb 1, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions apispec/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from .exceptions import APISpecError, PluginMethodNotImplementedError, DuplicateComponentNameError
from .utils import OpenAPIVersion, deepupdate

VALID_METHODS = [
VALID_METHODS_OPENAPI_V2 = [
'get',
'post',
'put',
Expand All @@ -16,6 +16,13 @@
'options',
]

VALID_METHODS_OPENAPI_V3 = VALID_METHODS_OPENAPI_V2 + ['trace']

VALID_METHODS = {
2: VALID_METHODS_OPENAPI_V2,
3: VALID_METHODS_OPENAPI_V3,
}


def clean_operations(operations, openapi_major_version):
"""Ensure that all parameters with "in" equal to "path" are also required
Expand All @@ -29,7 +36,7 @@ def clean_operations(operations, openapi_major_version):
to use. Supported values are 2 and 3.
"""
invalid = {key for key in
set(iterkeys(operations)) - set(VALID_METHODS)
set(iterkeys(operations)) - set(VALID_METHODS[openapi_major_version])
if not key.startswith('x-')}
if invalid:
raise APISpecError(
Expand Down