From fe4f81ebcfe77d44bb36457b38dfb1a6adcc5c9d Mon Sep 17 00:00:00 2001 From: Jeongho Nam Date: Wed, 4 Dec 2024 15:11:35 +0900 Subject: [PATCH] Fix #104: conversion OpenAPI version when `allOf.length` is 1. --- examples/v2.0/semanticscholar.json | 1983 +++++++++++++++++ package.json | 2 +- src/converters/OpenApiV3Upgrader.ts | 3 +- src/converters/OpenApiV3_1Emender.ts | 3 +- src/converters/SwaggerV2Upgrader.ts | 412 ++-- .../test_issue_104_upgrade_v20_allOf.ts | 21 + .../test_json_schema_convert_v20_example.ts | 4 +- 7 files changed, 2258 insertions(+), 170 deletions(-) create mode 100644 examples/v2.0/semanticscholar.json create mode 100644 test/features/issues/test_issue_104_upgrade_v20_allOf.ts diff --git a/examples/v2.0/semanticscholar.json b/examples/v2.0/semanticscholar.json new file mode 100644 index 0000000..d75b016 --- /dev/null +++ b/examples/v2.0/semanticscholar.json @@ -0,0 +1,1983 @@ +{ + "swagger": "2.0", + "basePath": "/graph/v1", + "paths": { + "/author/batch": { + "parameters": [ + { + "in": "query", + "description": "A comma-separated list of the fields to be returned. See the contents of Response Schema below for a list of all available fields that can be returned.\nThe authorId field is always returned. If the fields parameter is omitted, only the authorId and name will be returned.\n

Use a period (“.”) for subfields of papers.

\nExamples:\n

", + "name": "fields", + "type": "string" + } + ], + "post": { + "responses": { + "200": { + "description": "List of authors with default or requested fields", + "schema": { + "$ref": "#/definitions/AuthorWithPapers" + } + }, + "400": { + "description": "Bad query parameters", + "schema": { + "$ref": "#/definitions/Error400" + } + } + }, + "summary": "Get details for multiple authors at once", + "description": "* Fields is a single-value string parameter, not a multi-value one.\n* It is a query parameter, not to be submitted in the POST request's body.\n\nIn python:\n\n r = requests.post(\n 'https://api.semanticscholar.org/graph/v1/author/batch',\n params={'fields': 'name,hIndex,citationCount'},\n json={\"ids\":[\"1741101\", \"1780531\"]}\n )\n print(json.dumps(r.json(), indent=2))\n\n [\n {\n \"authorId\": \"1741101\",\n \"name\": \"Oren Etzioni\",\n \"citationCount\": 34803,\n \"hIndex\": 86\n },\n {\n \"authorId\": \"1780531\",\n \"name\": \"Daniel S. Weld\",\n \"citationCount\": 35526,\n \"hIndex\": 89\n }\n ]\n\nOther Examples:\n\n
\nLimitations:\n", + "operationId": "post_graph_get_authors", + "parameters": [ + { + "name": "payload", + "required": true, + "in": "body", + "schema": { + "$ref": "#/definitions/AuthorIdList" + } + } + ], + "tags": [ + "Author Data" + ] + } + }, + "/author/search": { + "parameters": [ + { + "default": 0, + "type": "integer", + "in": "query", + "description": "Used for pagination. When returning a list of results, start with the element at this position in the list.", + "name": "offset" + }, + { + "default": 100, + "type": "integer", + "in": "query", + "description": "The maximum number of results to return.
\nMust be <= 1000", + "name": "limit" + }, + { + "in": "query", + "description": "A comma-separated list of the fields to be returned. See the contents of the data array in Response Schema below for a list of all available fields that can be returned.\nThe authorId field is always returned. If the fields parameter is omitted, only the authorId and name will be returned.\n

Use a period (“.”) for subfields of papers.

\nExamples:\n

", + "name": "fields", + "type": "string" + }, + { + "required": true, + "in": "query", + "description": "A plain-text search query string.\n* No special query syntax is supported.\n* Hyphenated query terms yield no matches (replace it with space to find matches)", + "name": "query", + "type": "string" + } + ], + "get": { + "responses": { + "200": { + "description": "Batch of authors with default or requested fields", + "schema": { + "$ref": "#/definitions/AuthorSearchBatch" + } + }, + "400": { + "description": "Bad query parameters", + "schema": { + "$ref": "#/definitions/Error400" + } + } + }, + "summary": "Search for authors by name", + "description": "Specifying papers fields in the request will return all papers linked to each author in the results. Set a limit on the search results to reduce output size and latency.

\nExamples:\n", + "operationId": "get_graph_paper_title_search", + "tags": [ + "Paper Data" + ] + } + }, + "/paper/{paper_id}": { + "parameters": [ + { + "description": "The following types of IDs are supported:\n\n\nURLs are recognized from the following sites:\n", + "name": "paper_id", + "in": "path", + "required": true, + "type": "string" + }, + { + "description": "A comma-separated list of the fields to be returned. See the contents of Response Schema below for a list of all available fields that can be returned.\nThe paperId field is always returned. If the fields parameter is omitted, only the paperId and title will be returned.\n

Use a period (“.”) for fields that have version numbers or subfields, such as the embedding, authors, citations, and references fields:\n

\nExamples:\n", + "name": "fields", + "type": "string", + "in": "query" + } + ], + "get": { + "responses": { + "200": { + "description": "Paper with default or requested fields", + "schema": { + "$ref": "#/definitions/FullPaper" + } + }, + "400": { + "description": "Bad query parameters", + "schema": { + "$ref": "#/definitions/Error400" + } + }, + "404": { + "description": "Bad paper id", + "schema": { + "$ref": "#/definitions/Error404" + } + } + }, + "summary": "Details about a paper", + "description": "Examples:\n", + "operationId": "get_graph_get_paper", + "tags": [ + "Paper Data" + ] + } + }, + "/paper/{paper_id}/authors": { + "parameters": [ + { + "default": 0, + "type": "integer", + "in": "query", + "description": "Used for pagination. When returning a list of results, start with the element at this position in the list.", + "name": "offset" + }, + { + "default": 100, + "type": "integer", + "in": "query", + "description": "The maximum number of results to return.
\nMust be <= 1000", + "name": "limit" + }, + { + "in": "query", + "description": "A comma-separated list of the fields to be returned. See the contents of the data array in Response Schema below for a list of all available fields that can be returned.\nThe authorId field is always returned. If the fields parameter is omitted, only the authorId and name will be returned.\n

Use a period (“.”) for subfields of papers.

\nExamples:\n

", + "name": "fields", + "type": "string" + }, + { + "in": "path", + "description": "The following types of IDs are supported:\n\n\nURLs are recognized from the following sites:\n", + "name": "paper_id", + "required": true, + "type": "string" + } + ], + "get": { + "responses": { + "200": { + "description": "List of Authors with default or requested fields", + "schema": { + "$ref": "#/definitions/AuthorBatch" + } + }, + "400": { + "description": "Bad query parameters", + "schema": { + "$ref": "#/definitions/Error400" + } + }, + "404": { + "description": "Bad paper id", + "schema": { + "$ref": "#/definitions/Error404" + } + } + }, + "summary": "Details about a paper's authors", + "description": "Examples:\n", + "operationId": "get_graph_get_paper_authors", + "tags": [ + "Paper Data" + ] + } + }, + "/paper/{paper_id}/citations": { + "parameters": [ + { + "default": 0, + "type": "integer", + "in": "query", + "description": "Used for pagination. When returning a list of results, start with the element at this position in the list.", + "name": "offset" + }, + { + "default": 100, + "type": "integer", + "in": "query", + "description": "The maximum number of results to return.
\nMust be <= 1000", + "name": "limit" + }, + { + "in": "query", + "description": "A comma-separated list of the fields to be returned. See the contents of the data array in Response Schema below for a list of all available fields that can be returned.\nIf the fields parameter is omitted, only the paperId and title will be returned.\n

Request fields nested within citedPaper the same way as fields like contexts.

\nExamples:\n

", + "name": "fields", + "type": "string" + }, + { + "in": "path", + "description": "The following types of IDs are supported:\n\n\nURLs are recognized from the following sites:\n", + "name": "paper_id", + "required": true, + "type": "string" + } + ], + "get": { + "responses": { + "200": { + "description": "Batch of citations with default or requested fields", + "schema": { + "$ref": "#/definitions/CitationBatch" + } + }, + "400": { + "description": "Bad query parameters", + "schema": { + "$ref": "#/definitions/Error400" + } + }, + "404": { + "description": "Bad paper id", + "schema": { + "$ref": "#/definitions/Error404" + } + } + }, + "summary": "Details about a paper's citations", + "description": "Fetch details about the papers the cite this paper (i.e. papers in whose bibliography this paper appears)\n

\nExamples:\n", + "operationId": "get_graph_get_paper_citations", + "tags": [ + "Paper Data" + ] + } + }, + "/paper/{paper_id}/references": { + "parameters": [ + { + "default": 0, + "type": "integer", + "in": "query", + "description": "Used for pagination. When returning a list of results, start with the element at this position in the list.", + "name": "offset" + }, + { + "default": 100, + "type": "integer", + "in": "query", + "description": "The maximum number of results to return.
\nMust be <= 1000", + "name": "limit" + }, + { + "in": "query", + "description": "A comma-separated list of the fields to be returned. See the contents of the data array in Response Schema below for a list of all available fields that can be returned.\nIf the fields parameter is omitted, only the paperId and title will be returned.\n

Request fields nested within citedPaper the same way as fields like contexts.

\nExamples:\n

", + "name": "fields", + "type": "string" + }, + { + "in": "path", + "description": "The following types of IDs are supported:\n\n\nURLs are recognized from the following sites:\n", + "name": "paper_id", + "required": true, + "type": "string" + } + ], + "get": { + "responses": { + "200": { + "description": "Batch of references with default or requested fields", + "schema": { + "$ref": "#/definitions/ReferenceBatch" + } + }, + "400": { + "description": "Bad query parameters", + "schema": { + "$ref": "#/definitions/Error400" + } + }, + "404": { + "description": "Bad paper id", + "schema": { + "$ref": "#/definitions/Error404" + } + } + }, + "summary": "Details about a paper's references", + "description": "Fetch details about the papers cited by this paper (i.e. appearing in this paper's bibliography)\n

\nExamples:\n", + "operationId": "get_graph_get_paper_references", + "tags": [ + "Paper Data" + ] + } + } + }, + "info": { + "title": "Academic Graph API", + "version": "1.0", + "description": "Fetch paper and author data from the Semantic Scholar Academic Graph (S2AG).\n

\n Some things to note:\n