From 2bdd1ab6a1be359ce93305440cb246c1e82a0751 Mon Sep 17 00:00:00 2001 From: "T. Franzel" <13507857+tfranzel@users.noreply.github.com> Date: Thu, 14 May 2020 16:28:44 +0200 Subject: [PATCH] alphanumeric component sorting. sry for the changing schema but it was inconsistent. this will not change anymore. --- drf_spectacular/plumbing.py | 4 +- tests/contrib/test_drf_jwt.yml | 10 ++--- tests/contrib/test_oauth_toolkit.yml | 24 ++++++------ tests/contrib/test_rest_polymorphic.yml | 52 ++++++++++++------------- tests/contrib/test_simplejwt.yml | 10 ++--- tests/test_basic.yml | 48 +++++++++++------------ tests/test_extend_schema.yml | 46 +++++++++++----------- tests/test_fields.yml | 16 ++++---- tests/test_polymorphic.yml | 34 ++++++++-------- tests/test_postprocessing.yml | 16 ++++---- tests/test_recursion.yml | 16 ++++---- tests/test_versioning_v1.yml | 16 ++++---- tests/test_versioning_v2.yml | 16 ++++---- 13 files changed, 154 insertions(+), 154 deletions(-) diff --git a/drf_spectacular/plumbing.py b/drf_spectacular/plumbing.py index a16a219a..437e0481 100644 --- a/drf_spectacular/plumbing.py +++ b/drf_spectacular/plumbing.py @@ -359,8 +359,8 @@ def build(self, extra_components) -> dict: output[extra_type][component_name] = component_schema # sort by component type then by name return { - type: {name: output[type][name] for name in output[type].keys()} - for type in sorted(output.keys(), reverse=True) + type: {name: output[type][name] for name in sorted(output[type].keys())} + for type in sorted(output.keys()) } diff --git a/tests/contrib/test_drf_jwt.yml b/tests/contrib/test_drf_jwt.yml index 6ee0afde..07fbd920 100644 --- a/tests/contrib/test_drf_jwt.yml +++ b/tests/contrib/test_drf_jwt.yml @@ -50,11 +50,6 @@ paths: $ref: '#/components/schemas/X' description: '' components: - securitySchemes: - jwtAuth: - type: http - scheme: bearer - bearerFormat: Bearer schemas: JSONWebToken: type: object @@ -79,3 +74,8 @@ components: format: uuid required: - uuid + securitySchemes: + jwtAuth: + type: http + scheme: bearer + bearerFormat: Bearer diff --git a/tests/contrib/test_oauth_toolkit.yml b/tests/contrib/test_oauth_toolkit.yml index 9bf1e1dc..885d91f4 100644 --- a/tests/contrib/test_oauth_toolkit.yml +++ b/tests/contrib/test_oauth_toolkit.yml @@ -59,7 +59,19 @@ paths: $ref: '#/components/schemas/X' description: '' components: + schemas: + X: + type: object + properties: + uuid: + type: string + format: uuid + required: + - uuid securitySchemes: + basicAuth: + type: http + scheme: basic oauth2: type: oauth2 flows: @@ -70,15 +82,3 @@ components: read: Reading scope write: Writing scope extra_scope: Extra Scope - basicAuth: - type: http - scheme: basic - schemas: - X: - type: object - properties: - uuid: - type: string - format: uuid - required: - - uuid diff --git a/tests/contrib/test_rest_polymorphic.yml b/tests/contrib/test_rest_polymorphic.yml index a790c799..e64b6313 100644 --- a/tests/contrib/test_rest_polymorphic.yml +++ b/tests/contrib/test_rest_polymorphic.yml @@ -161,24 +161,7 @@ paths: '204': description: No response body components: - securitySchemes: - cookieAuth: - type: apiKey - in: cookie - name: Session - basicAuth: - type: http - scheme: basic schemas: - Person: - oneOf: - - $ref: '#/components/schemas/LegalPerson' - - $ref: '#/components/schemas/NaturalPerson' - discriminator: - propertyName: resourcetype - mapping: - legal: '#/components/schemas/LegalPerson' - natural: '#/components/schemas/NaturalPerson' LegalPerson: type: object properties: @@ -222,15 +205,6 @@ components: - last_name - address - supervisor_id - PatchedPerson: - oneOf: - - $ref: '#/components/schemas/PatchedLegalPerson' - - $ref: '#/components/schemas/PatchedNaturalPerson' - discriminator: - propertyName: resourcetype - mapping: - legal: '#/components/schemas/PatchedLegalPerson' - natural: '#/components/schemas/PatchedNaturalPerson' PatchedLegalPerson: type: object properties: @@ -266,3 +240,29 @@ components: supervisor_id: type: integer nullable: true + PatchedPerson: + oneOf: + - $ref: '#/components/schemas/PatchedLegalPerson' + - $ref: '#/components/schemas/PatchedNaturalPerson' + discriminator: + propertyName: resourcetype + mapping: + legal: '#/components/schemas/PatchedLegalPerson' + natural: '#/components/schemas/PatchedNaturalPerson' + Person: + oneOf: + - $ref: '#/components/schemas/LegalPerson' + - $ref: '#/components/schemas/NaturalPerson' + discriminator: + propertyName: resourcetype + mapping: + legal: '#/components/schemas/LegalPerson' + natural: '#/components/schemas/NaturalPerson' + securitySchemes: + basicAuth: + type: http + scheme: basic + cookieAuth: + type: apiKey + in: cookie + name: Session diff --git a/tests/contrib/test_simplejwt.yml b/tests/contrib/test_simplejwt.yml index a7507d3b..8354243f 100644 --- a/tests/contrib/test_simplejwt.yml +++ b/tests/contrib/test_simplejwt.yml @@ -78,11 +78,6 @@ paths: $ref: '#/components/schemas/X' description: '' components: - securitySchemes: - jwtAuth: - type: http - scheme: bearer - bearerFormat: Bearer schemas: TokenObtainPair: type: object @@ -110,3 +105,8 @@ components: format: uuid required: - uuid + securitySchemes: + jwtAuth: + type: http + scheme: bearer + bearerFormat: Bearer diff --git a/tests/test_basic.yml b/tests/test_basic.yml index a2c51898..3a797faa 100644 --- a/tests/test_basic.yml +++ b/tests/test_basic.yml @@ -184,11 +184,6 @@ paths: '200': description: No response body components: - securitySchemes: - tokenAuth: - type: http - scheme: bearer - bearerFormat: Token schemas: Album: type: object @@ -220,25 +215,6 @@ components: - genre - year - released - Song: - type: object - properties: - id: - type: string - format: uuid - readOnly: true - title: - type: string - maxLength: 100 - length: - type: integer - top10: - type: boolean - nullable: true - readOnly: true - required: - - title - - length PatchedAlbum: type: object properties: @@ -264,8 +240,32 @@ components: type: integer released: type: boolean + Song: + type: object + properties: + id: + type: string + format: uuid + readOnly: true + title: + type: string + maxLength: 100 + length: + type: integer + top10: + type: boolean + nullable: true + readOnly: true + required: + - title + - length GenreEnum: enum: - POP - ROCK type: string + securitySchemes: + tokenAuth: + type: http + scheme: bearer + bearerFormat: Token diff --git a/tests/test_extend_schema.yml b/tests/test_extend_schema.yml index fd26b710..331c1dd1 100644 --- a/tests/test_extend_schema.yml +++ b/tests/test_extend_schema.yml @@ -236,14 +236,6 @@ paths: '201': description: No response body components: - securitySchemes: - cookieAuth: - type: apiKey - in: cookie - name: Session - basicAuth: - type: http - scheme: basic schemas: Alpha: type: object @@ -269,17 +261,13 @@ components: - field_a - field_b - field_c - Gamma: + Delta: type: object properties: - encoding: - type: string - image_data: + field_a: type: string - format: byte - required: - - encoding - - image_data + field_b: + type: integer ErrorDetail: type: object properties: @@ -300,6 +288,17 @@ components: allOf: - $ref: '#/components/schemas/FieldLEnum' readOnly: true + Gamma: + type: object + properties: + encoding: + type: string + image_data: + type: string + format: byte + required: + - encoding + - image_data Inline: type: object properties: @@ -310,13 +309,6 @@ components: required: - inline_b - inline_i - Delta: - type: object - properties: - field_a: - type: string - field_b: - type: integer Query: type: object properties: @@ -346,3 +338,11 @@ components: - a - b type: string + securitySchemes: + basicAuth: + type: http + scheme: basic + cookieAuth: + type: apiKey + in: cookie + name: Session diff --git a/tests/test_fields.yml b/tests/test_fields.yml index 6f5a3d76..b1742c97 100644 --- a/tests/test_fields.yml +++ b/tests/test_fields.yml @@ -47,14 +47,6 @@ paths: $ref: '#/components/schemas/AllFields' description: '' components: - securitySchemes: - cookieAuth: - type: apiKey - in: cookie - name: Session - basicAuth: - type: http - scheme: basic schemas: AllFields: type: object @@ -209,3 +201,11 @@ components: - field_foreign - field_o2o - field_m2m + securitySchemes: + basicAuth: + type: http + scheme: basic + cookieAuth: + type: apiKey + in: cookie + name: Session diff --git a/tests/test_polymorphic.yml b/tests/test_polymorphic.yml index 0753b7f6..5443d3e5 100644 --- a/tests/test_polymorphic.yml +++ b/tests/test_polymorphic.yml @@ -32,24 +32,7 @@ paths: $ref: '#/components/schemas/MetaPerson' description: '' components: - securitySchemes: - cookieAuth: - type: apiKey - in: cookie - name: Session - basicAuth: - type: http - scheme: basic schemas: - MetaPerson: - oneOf: - - $ref: '#/components/schemas/LegalPerson' - - $ref: '#/components/schemas/NaturalPerson' - discriminator: - propertyName: type - mapping: - legal: '#/components/schemas/LegalPerson' - natural: '#/components/schemas/NaturalPerson' LegalPerson: type: object properties: @@ -64,6 +47,15 @@ components: readOnly: true required: - company_name + MetaPerson: + oneOf: + - $ref: '#/components/schemas/LegalPerson' + - $ref: '#/components/schemas/NaturalPerson' + discriminator: + propertyName: type + mapping: + legal: '#/components/schemas/LegalPerson' + natural: '#/components/schemas/NaturalPerson' NaturalPerson: type: object properties: @@ -82,3 +74,11 @@ components: required: - first_name - last_name + securitySchemes: + basicAuth: + type: http + scheme: basic + cookieAuth: + type: apiKey + in: cookie + name: Session diff --git a/tests/test_postprocessing.yml b/tests/test_postprocessing.yml index d849bfd6..18e1be37 100644 --- a/tests/test_postprocessing.yml +++ b/tests/test_postprocessing.yml @@ -40,14 +40,6 @@ paths: $ref: '#/components/schemas/B' description: '' components: - securitySchemes: - cookieAuth: - type: apiKey - in: cookie - name: Session - basicAuth: - type: http - scheme: basic schemas: A: type: object @@ -70,3 +62,11 @@ components: - ru - cn type: string + securitySchemes: + basicAuth: + type: http + scheme: basic + cookieAuth: + type: apiKey + in: cookie + name: Session diff --git a/tests/test_recursion.yml b/tests/test_recursion.yml index c1ba8bfe..4c4fa5dd 100644 --- a/tests/test_recursion.yml +++ b/tests/test_recursion.yml @@ -29,14 +29,6 @@ paths: $ref: '#/components/schemas/TreeNode' description: '' components: - securitySchemes: - cookieAuth: - type: apiKey - in: cookie - name: Session - basicAuth: - type: http - scheme: basic schemas: TreeNode: type: object @@ -58,3 +50,11 @@ components: required: - label - children + securitySchemes: + basicAuth: + type: http + scheme: basic + cookieAuth: + type: apiKey + in: cookie + name: Session diff --git a/tests/test_versioning_v1.yml b/tests/test_versioning_v1.yml index 5b983728..c67f6ea8 100644 --- a/tests/test_versioning_v1.yml +++ b/tests/test_versioning_v1.yml @@ -23,14 +23,6 @@ paths: $ref: '#/components/schemas/Xv1' description: '' components: - securitySchemes: - cookieAuth: - type: apiKey - in: cookie - name: Session - basicAuth: - type: http - scheme: basic schemas: Xv1: type: object @@ -39,3 +31,11 @@ components: type: integer required: - id + securitySchemes: + basicAuth: + type: http + scheme: basic + cookieAuth: + type: apiKey + in: cookie + name: Session diff --git a/tests/test_versioning_v2.yml b/tests/test_versioning_v2.yml index 4b348f4b..88e37914 100644 --- a/tests/test_versioning_v2.yml +++ b/tests/test_versioning_v2.yml @@ -23,14 +23,6 @@ paths: $ref: '#/components/schemas/Xv2' description: '' components: - securitySchemes: - cookieAuth: - type: apiKey - in: cookie - name: Session - basicAuth: - type: http - scheme: basic schemas: Xv2: type: object @@ -40,3 +32,11 @@ components: format: uuid required: - id + securitySchemes: + basicAuth: + type: http + scheme: basic + cookieAuth: + type: apiKey + in: cookie + name: Session