diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 00000000..764d824d --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,27 @@ +name: CI + +on: + pull_request: + branches: + - next + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v1 + + - name: use node + uses: actions/setup-node@v1 + with: + node-version: 10 + + - name: install deps + run: npm i + + - name: simple-tests + run: npm run generate && npm run validate + + - name: specific-tests + run: npm run test-specific diff --git a/.prettierignore b/.prettierignore index 3856c7dd..1f99545e 100644 --- a/.prettierignore +++ b/.prettierignore @@ -4,4 +4,10 @@ tests/**/*.d.js swagger-test-cli swagger-test-cli.* templates -*.md \ No newline at end of file +*.md +.github +node_modules +.openapi-generator +.vscode +assets +templates \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json index 16b0536e..758ad138 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -18,7 +18,7 @@ "request": "launch", "cwd": "${workspaceFolder}", "runtimeExecutable": "npm", - "runtimeArgs": ["run-script", "cli:debug:json"] + "runtimeArgs": ["run-script", "cli:json"] }, { "name": "Debug YAML CLI", @@ -26,7 +26,7 @@ "request": "launch", "cwd": "${workspaceFolder}", "runtimeExecutable": "npm", - "runtimeArgs": ["run-script", "cli:debug:yaml"] + "runtimeArgs": ["run-script", "cli:yaml"] }, { "name": "Debug Node", diff --git a/CHANGELOG.md b/CHANGELOG.md index ab1ff7ac..6ac7fecd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,20 @@ # next release +# 6.4.0 + +Features: +- `onFormatRouteName(routeInfo: RawRouteInfo, templateRouteName: string)` hook. Allows to format route name, as you like :) + +Fixes: +- Bug with wrong complex types (anyOf, oneOf, allOf) when some child schema contains only description + ![example](./assets/changelog_assets/fixComplexTypeAny.jpg) +- Bug with number enums which have `x-enumNames` +- Problem with not existing `title` property in `info` + +Minor: +- Improve description for complex types +- Improve description in single api file + # 6.3.0 Features: diff --git a/README.md b/README.md index 59632984..b95880ac 100644 --- a/README.md +++ b/README.md @@ -73,49 +73,53 @@ Also you can use `npx`: You can use this package from nodejs: ```js const { generateApi } = require('swagger-typescript-api'); +const path = require("path"); +const fs = require("fs"); -// example with url +/* NOTE: all fields are optional expect one of `output`, `url`, `spec` */ generateApi({ - name: "MySuperbApi.ts", // name of output typescript file - url: 'http://api.com/swagger.json', // url where located swagger schema -}) - .then(({ files, configuration }) => { - files.forEach(({ content, name }) => { - fs.writeFile(path, content); - }); - }) - .catch(e => console.error(e)) - -// example with local file -generateApi({ - name: "ApiModule.ts", // name of output typescript file - input: resolve(process.cwd(), './foo/swagger.json') // path to swagger schema -}) - .then(({ files, configuration }) => { - files.forEach(({ content, name }) => { - fs.writeFile(path, content); - }); - }) - .catch(e => console.error(e)) - -// example with parsed schema -generateApi({ - name: "ApiModule.ts", // name of output typescript file + name: "MySuperbApi.ts", + output: path.resolve(process.cwd(), "./src/__generated__"), + url: 'http://api.com/swagger.json', + input: path.resolve(process.cwd(), './foo/swagger.json'), spec: { swagger: "2.0", info: { version: "1.0.0", title: "Swagger Petstore", }, - host: "petstore.swagger.io", - basePath: "/api", - schemes: ["http"], - consumes: ["application/json"], - produces: ["application/json"], - paths: { - // ... - } // ... + }, + templates: path.resolve(process.cwd(), './api-templates'), + httpClientType: "axios", // or "fetch" + defaultResponseAsSuccess: false, + generateRouteTypes: false, + generateResponses: true, + toJS: false, + extractRequestParams: false, + prettier: { + printWidth: 120, + tabWidth: 2, + trailingComma: "all", + parser: "typescript", + }, + defaultResponseType: "void", + singleHttpClient: true, + cleanOutput: false, + enumNamesAsValues: false, + moduleNameFirstTag: false, + generateUnionEnums: false, + extraTemplates: [], + hooks: { + onCreateComponent: (component) => {}, + onCreateRequestParams: (rawType) => {}, + onCreateRoute: (routeData) => {}, + onCreateRouteName: (routeNameInfo, rawRouteInfo) => {}, + onFormatRouteName: (routeInfo, templateRouteName) => {}, + onFormatTypeName: (typeName, rawTypeName) => {}, + onInit: (configuration) => {}, + onParseSchema: (originalSchema, parsedSchema) => {}, + onPrepareConfig: (currentConfiguration) => {}, } }) .then(({ files, configuration }) => { diff --git a/assets/changelog_assets/fixComplexTypeAny.jpg b/assets/changelog_assets/fixComplexTypeAny.jpg new file mode 100644 index 00000000..11fb9d70 Binary files /dev/null and b/assets/changelog_assets/fixComplexTypeAny.jpg differ diff --git a/index.d.ts b/index.d.ts index 00893650..0ef77268 100644 --- a/index.d.ts +++ b/index.d.ts @@ -84,7 +84,6 @@ interface GenerateApiParams { * extract request params to data contract (Also combine path params and query params into one object) */ extractRequestParams?: boolean; - prepareConfig?: (currentConfiguration: C) => C; /** * prettier configuration */ @@ -100,29 +99,32 @@ interface GenerateApiParams { cleanOutput?: boolean; enumNamesAsValues?: boolean; - hooks?: Partial<{ - onCreateComponent: (component: SchemaComponent) => SchemaComponent | void; - onParseSchema: (originalSchema: any, parsedSchema: any) => any | void; - onCreateRoute: (routeData: ParsedRoute) => ParsedRoute | void; - /** Start point of work this tool (after fetching schema) */ - onInit?: (configuration: C) => C | void; - /** customize configuration object before sending it to ETA templates */ - onPrepareConfig?: (currentConfiguration: C) => C | void; - onCreateRouteName?: ( - routeNameInfo: RouteNameInfo, - rawRouteInfo: RawRouteInfo, - ) => RouteNameInfo | void; - onCreateRequestParams?: ( - rawType: SchemaComponent["rawTypeData"], - ) => SchemaComponent["rawTypeData"] | void; - onFormatTypeName?: (typeName: string, rawTypeName?: string) => string | void; - }>; + hooks?: Partial; /** * extra templates */ extraTemplates?: { name: string; path: string }[]; } +export interface Hooks { + onCreateComponent: (component: SchemaComponent) => SchemaComponent | void; + onParseSchema: (originalSchema: any, parsedSchema: any) => any | void; + onCreateRoute: (routeData: ParsedRoute) => ParsedRoute | void; + /** Start point of work this tool (after fetching schema) */ + onInit?: (configuration: C) => C | void; + /** customize configuration object before sending it to ETA templates */ + onPrepareConfig?: (currentConfiguration: C) => C | void; + onCreateRouteName?: ( + routeNameInfo: RouteNameInfo, + rawRouteInfo: RawRouteInfo, + ) => RouteNameInfo | void; + onCreateRequestParams?: ( + rawType: SchemaComponent["rawTypeData"], + ) => SchemaComponent["rawTypeData"] | void; + onFormatTypeName?: (typeName: string, rawTypeName?: string) => string | void; + onFormatRouteName?: (routeInfo: RawRouteInfo, templateRouteName: string) => string | void; +} + export interface RouteNameRouteInfo {} export type RouteNameInfo = { diff --git a/package-lock.json b/package-lock.json index 4cfd05c6..9eb92c94 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "swagger-typescript-api", - "version": "6.3.0", + "version": "6.4.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 75cea76c..4f17ca87 100644 --- a/package.json +++ b/package.json @@ -1,17 +1,16 @@ { "name": "swagger-typescript-api", - "version": "6.3.0", - "description": "Create typescript api module from swagger schema", + "version": "6.4.0", + "description": "Generate typescript/javascript api from swagger schema", "scripts": { - "cli:json": "node index.js -r -d -p ./swagger-test-cli.json -n swagger-test-cli.ts --extract-request-params --enum-names-as-values", + "cli:json": "node index.js -r -d -p ./swagger-test-cli.json -n swagger-test-cli.ts", "cli:yaml": "node index.js -r -d -p ./swagger-test-cli.yaml -n swagger-test-cli.ts", - "cli:debug:json": "node --nolazy index.js -r -d -p ./swagger-test-cli.json -n swagger-test-cli.ts --extract-request-params --enum-names-as-values", - "cli:debug:yaml": "node --nolazy index.js -p ./swagger-test-cli.yaml -n swagger-test-cli.ts", "node": "node swagger-test-cli/generate.js", "node:debug": "node --nolazy swagger-test-cli/generate.js", "contributors": "all-contributors generate", "cli:help": "node index.js -h", "test-all": "node ./node_modules/npm-run-all/bin/npm-run-all/index.js generate validate test:* --continue-on-error", + "test-specific": "node ./node_modules/npm-run-all/bin/npm-run-all/index.js test:* --continue-on-error", "generate": "node tests/generate.js", "generate:debug": "node --nolazy tests/generate.js", "validate": "node tests/validate.js", diff --git a/src/apiConfig.js b/src/apiConfig.js index b91fdb6a..cde8fa0c 100644 --- a/src/apiConfig.js +++ b/src/apiConfig.js @@ -3,7 +3,7 @@ const { formatDescription } = require("./common"); const { TS_KEYWORDS } = require("./constants"); const createApiConfig = (swaggerSchema) => { - const { info, servers, host, basePath } = swaggerSchema; + const { info, servers, host, basePath, externalDocs, tags } = swaggerSchema; const server = (servers && servers[0]) || { url: "" }; const { title = "No title", version, description: schemaDescription = "" } = info || {}; const { url: serverUrl } = server; @@ -27,6 +27,14 @@ const createApiConfig = (swaggerSchema) => { servers: servers || [], basePath, host, + externalDocs: _.merge( + { + url: "", + description: "", + }, + externalDocs, + ), + tags: _.compact(tags), // TODO: unused, remove! props: _.compact([ { @@ -50,7 +58,9 @@ const createApiConfig = (swaggerSchema) => { baseUrl: serverUrl, title, version, + // TODO: unused, remove description, + // TODO: unused, remove hasDescription: !!description.length, }; }; diff --git a/src/config.js b/src/config.js index 1cca3597..c0317a70 100644 --- a/src/config.js +++ b/src/config.js @@ -50,6 +50,7 @@ const config = { onCreateRequestParams: (rawType) => {}, onCreateRouteName: () => {}, onFormatTypeName: (typeName, rawTypeName) => {}, + onFormatRouteName: (routeInfo, templateRouteName) => {}, }, defaultResponseType: TS_KEYWORDS.VOID, singleHttpClient: false, diff --git a/src/constants.js b/src/constants.js index 7795bb6e..9bfe48aa 100644 --- a/src/constants.js +++ b/src/constants.js @@ -29,6 +29,7 @@ const SCHEMA_TYPES = { COMPLEX_ANY_OF: "anyOf", COMPLEX_ALL_OF: "allOf", COMPLEX_NOT: "not", + COMPLEX_UNKNOWN: "__unknown", }; const HTTP_CLIENT = { diff --git a/src/routeNames.js b/src/routeNames.js index fe88c217..a03156f6 100644 --- a/src/routeNames.js +++ b/src/routeNames.js @@ -6,15 +6,15 @@ const getRouteName = (routeInfo) => { const { routeNameDuplicatesMap, templatesToRender } = config; const routeNameTemplate = templatesToRender.routeName; - if (!routeNameTemplate) { - throw new Error("🥵 route name template (route-name.eta) not found"); - } - - const routeName = renderTemplate(routeNameTemplate, { + const routeNameFromTemplate = renderTemplate(routeNameTemplate, { routeInfo: routeInfo, utils: require("./render/utils"), + config, }); + const routeName = + config.hooks.onFormatRouteName(routeInfo, routeNameFromTemplate) || routeNameFromTemplate; + const duplicateIdentifier = `${moduleName}|${routeName}`; if (routeNameDuplicatesMap.has(duplicateIdentifier)) { diff --git a/src/schema.js b/src/schema.js index 70216932..2415741d 100644 --- a/src/schema.js +++ b/src/schema.js @@ -131,10 +131,9 @@ const getObjectTypeContent = (schema) => { $$raw: property, description: _.compact([ property.description || + _.compact(_.map(property[getComplexType(property)], "description"))[0] || rawTypeData.description || - _.compact(_.map(rawTypeData.allOf, "description"))[0] || - _.compact(_.map(rawTypeData.oneOf, "description"))[0] || - _.compact(_.map(rawTypeData.anyOf, "description"))[0] || + _.compact(_.map(rawTypeData[getComplexType(rawTypeData)], "description"))[0] || "", !_.isUndefined(property.format) && `@format ${property.format}`, !_.isUndefined(property.minimum) && `@min ${property.minimum}`, @@ -168,24 +167,34 @@ const getObjectTypeContent = (schema) => { return propertiesContent; }; -const complexTypeGetter = ({ description, ...schema }) => getInlineParseContent(schema); +const complexTypeGetter = (schema) => getInlineParseContent(schema); +const filterContents = (contents, types) => _.filter(contents, (type) => !_.includes(types, type)); const complexSchemaParsers = { [SCHEMA_TYPES.COMPLEX_ONE_OF]: (schema) => { // T1 | T2 const combined = _.map(schema.oneOf, complexTypeGetter); - return checkAndAddNull(schema, combined.join(" | ")); + + return checkAndAddNull(schema, filterContents(combined, [TS_KEYWORDS.ANY]).join(" | ")); }, [SCHEMA_TYPES.COMPLEX_ALL_OF]: (schema) => { // T1 & T2 - return checkAndAddNull(schema, _.map(schema.allOf, complexTypeGetter).join(" & ")); + const combined = _.map(schema.allOf, complexTypeGetter); + return checkAndAddNull( + schema, + filterContents(combined, [...JS_EMPTY_TYPES, ...JS_PRIMITIVE_TYPES, TS_KEYWORDS.ANY]).join( + " & ", + ), + ); }, [SCHEMA_TYPES.COMPLEX_ANY_OF]: (schema) => { // T1 | T2 | (T1 & T2) const combined = _.map(schema.anyOf, complexTypeGetter); - const nonEmptyTypesCombined = combined.filter( - (type) => !JS_EMPTY_TYPES.includes(type) && !JS_PRIMITIVE_TYPES.includes(type), - ); + const nonEmptyTypesCombined = filterContents(combined, [ + ...JS_EMPTY_TYPES, + ...JS_PRIMITIVE_TYPES, + TS_KEYWORDS.ANY, + ]); return checkAndAddNull( schema, `${combined.join(" | ")}` + @@ -206,7 +215,7 @@ const getComplexType = (schema) => { // TODO :( if (schema.not) return SCHEMA_TYPES.COMPLEX_NOT; - throw new Error("Unknown complex type"); + return SCHEMA_TYPES.COMPLEX_UNKNOWN; }; const attachParsedRef = (originalSchema, parsedSchema) => { @@ -228,25 +237,29 @@ const schemaParsers = { const isIntegerEnum = keyType === types.number; let content = null; - if (enumNamesAsValues && _.size(enumNames)) { - content = _.map(enumNames, (enumName, index) => ({ - key: formatModelName(enumName), - type: TS_KEYWORDS.STRING, - value: `"${enumName}"`, - })); - } else if (_.size(enumNames) > _.size(schema.enum)) { - content = _.map(enumNames, (enumName, index) => ({ - key: - (enumNames && enumNames[index]) || (isIntegerEnum ? enumName : formatModelName(enumName)), - type: keyType, - value: enumName === null ? enumName : isIntegerEnum ? `${enumName}` : `"${enumName}"`, - })); - } else { - content = _.map(schema.enum, (key, index) => { - const enumName = enumNames && enumNames[index]; + if (_.isArray(enumNames) && _.size(enumNames)) { + content = _.map(enumNames, (enumName, index) => { + const enumValue = _.get(schema.enum, index); + const formattedKey = (enumName && formatModelName(enumName)) || formatModelName(enumValue); + + if (enumNamesAsValues || _.isUndefined(enumValue)) { + return { + key: formattedKey, + type: TS_KEYWORDS.STRING, + value: `"${enumName}"`, + }; + } return { - key: enumName || (isIntegerEnum ? key : formatModelName(key)), + key: formattedKey, + type: keyType, + value: enumValue === null ? enumValue : isIntegerEnum ? `${enumValue}` : `"${enumValue}"`, + }; + }); + } else { + content = _.map(schema.enum, (key) => { + return { + key: isIntegerEnum ? key : formatModelName(key), type: keyType, value: key === null ? key : isIntegerEnum ? `${key}` : `"${key}"`, }; @@ -292,7 +305,9 @@ const schemaParsers = { type: SCHEMA_TYPES.PRIMITIVE, typeIdentifier: TS_KEYWORDS.TYPE, name: typeName, - description: formatDescription(schema.description), + description: formatDescription( + schema.description || _.compact(_.map(schema[complexType], "description"))[0] || "", + ), content: _.compact([ complexSchemaContent && `(${complexSchemaContent})`, diff --git a/src/swagger.js b/src/swagger.js index 5191be2c..2f4d1f1c 100644 --- a/src/swagger.js +++ b/src/swagger.js @@ -40,7 +40,17 @@ const getSwaggerObject = (pathToSwagger, urlToSwagger, disableStrictSSL) => const convertSwaggerObject = (swaggerSchema) => { return new Promise((resolve) => { + swaggerSchema.info = _.merge( + { + title: "No title", + version: "", + }, + swaggerSchema.info, + ); + if (!swaggerSchema.openapi) { + swaggerSchema.paths = _.merge({}, swaggerSchema.paths); + converter.convertObj( swaggerSchema, { diff --git a/templates/default/api.eta b/templates/default/api.eta index 3d30f61f..6220f43c 100644 --- a/templates/default/api.eta +++ b/templates/default/api.eta @@ -1,6 +1,6 @@ <% const { apiConfig, routes, utils, config } = it; -const { info, servers } = apiConfig; +const { info, servers, externalDocs } = apiConfig; const { _, require, formatDescription } = utils; const server = (servers && servers[0]) || { url: "" }; @@ -8,7 +8,19 @@ const server = (servers && servers[0]) || { url: "" }; const descriptionLines = _.compact([ `@title ${info.title || "No title"}`, info.version && `@version ${info.version}`, + info.license && `@license ${_.compact([ + info.license.name, + info.license.url && `(${info.license.url})`, + ]).join(" ")}`, + info.termsOfService && `@termsOfService ${info.termsOfService}`, server.url && `@baseUrl ${server.url}`, + externalDocs.url && `@externalDocs ${externalDocs.url}`, + info.contact && `@contact ${_.compact([ + info.contact.name, + info.contact.email && `<${info.contact.email}>`, + info.contact.url && `(${info.contact.url})`, + ]).join(" ")}`, + info.description && " ", info.description && _.replace(formatDescription(info.description), /\n/g, "\n * "), ]); diff --git a/tests/generated/v2.0/adafruit.ts b/tests/generated/v2.0/adafruit.ts index a1c5cc0a..28168aa2 100644 --- a/tests/generated/v2.0/adafruit.ts +++ b/tests/generated/v2.0/adafruit.ts @@ -359,6 +359,7 @@ export class HttpClient { * @title Adafruit IO * @version 2.0.0 * @baseUrl https://io.adafruit.com/api/v2 + * * ### The Internet of Things for Everyone * * The Adafruit IO HTTP API provides access to your Adafruit IO data from any programming language or hardware environment that can speak HTTP. The easiest way to get started is with [an Adafruit IO learn guide](https://learn.adafruit.com/series/adafruit-io-basics) and [a simple Internet of Things capable device like the Feather Huzzah](https://www.adafruit.com/product/2821). diff --git a/tests/generated/v2.0/another-example.ts b/tests/generated/v2.0/another-example.ts index ec32c8fd..35ce2068 100644 --- a/tests/generated/v2.0/another-example.ts +++ b/tests/generated/v2.0/another-example.ts @@ -334,7 +334,12 @@ export class HttpClient { /** * @title Swagger Petstore * @version 1.0.0 + * @license Apache-2.0 (http://www.apache.org/licenses/LICENSE-2.0.html) + * @termsOfService http://swagger.io/terms/ * @baseUrl http://petstore.swagger.io/v2 + * @externalDocs http://swagger.io + * @contact + * * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. */ export class Api extends HttpClient { diff --git a/tests/generated/v2.0/authentiq.ts b/tests/generated/v2.0/authentiq.ts index b264b04a..0c7dc0ef 100644 --- a/tests/generated/v2.0/authentiq.ts +++ b/tests/generated/v2.0/authentiq.ts @@ -255,7 +255,11 @@ export class HttpClient { /** * @title Authentiq * @version 6 + * @license Apache 2.0 (http://www.apache.org/licenses/LICENSE-2.0.html) + * @termsOfService http://authentiq.com/terms/ * @baseUrl https://6-dot-authentiqio.appspot.com + * @contact Authentiq team (http://authentiq.io/support) + * * Strong authentication, without the passwords. */ export class Api extends HttpClient { diff --git a/tests/generated/v2.0/enums.ts b/tests/generated/v2.0/enums.ts new file mode 100644 index 00000000..b55e589c --- /dev/null +++ b/tests/generated/v2.0/enums.ts @@ -0,0 +1,272 @@ +/* eslint-disable */ +/* tslint:disable */ +/* + * --------------------------------------------------------------- + * ## THIS FILE WAS GENERATED VIA SWAGGER-TYPESCRIPT-API ## + * ## ## + * ## AUTHOR: acacode ## + * ## SOURCE: https://github.com/acacode/swagger-typescript-api ## + * --------------------------------------------------------------- + */ + +export enum OnlyEnumNames { + Bla = "Bla", + Blabla = "Blabla", + Boiler = "Boiler", +} + +export enum StringOnlyEnumNames { + Bla = "Bla", + Blabla = "Blabla", + Boiler = "Boiler", +} + +export enum StringEnums { + Bla = "foo", + Blabla = "bar", + Boiler = "Boiler", +} + +export enum StringCompleteEnums { + Bla = "foo", + Blabla = "bar", + Boiler = "baz", +} + +/** + * @format int32 + */ +export enum EmptyEnum { + Bla = "Bla", + Blabla = "Blabla", + Boiler = "Boiler", +} + +/** + * @format int32 + */ +export enum EnumWithMoreNames { + Bla = 1, + Blabla = "Blabla", + Boiler = "Boiler", +} + +/** + * @format int32 + */ +export enum SomeInterestEnum { + Bla = 6, + Blabla = 2, + Boiler = 1, + Bbabab = 67, + Nowadays = 88, + FAIL = 122, + Vvvvv = 88, + ASdasAS = 0, + ASDsacZX = 213, + Zook = 12378, + EnumMm = 123125, + VCsa = 32452, + Yuuu = 1111, + ASddd = 66666, + ASdsdsa = "ASdsdsa", + ASDds = "ASDds", + HSDFDS = "HSDFDS", +} + +export type QueryParamsType = Record; +export type ResponseFormat = keyof Omit; + +export interface FullRequestParams extends Omit { + /** set parameter to `true` for call `securityWorker` for this request */ + secure?: boolean; + /** request path */ + path: string; + /** content type of request body */ + type?: ContentType; + /** query params */ + query?: QueryParamsType; + /** format of response (i.e. response.json() -> format: "json") */ + format?: ResponseFormat; + /** request body */ + body?: unknown; + /** base url */ + baseUrl?: string; + /** request cancellation token */ + cancelToken?: CancelToken; +} + +export type RequestParams = Omit; + +export interface ApiConfig { + baseUrl?: string; + baseApiParams?: Omit; + securityWorker?: (securityData: SecurityDataType | null) => Promise | RequestParams | void; +} + +export interface HttpResponse extends Response { + data: D; + error: E; +} + +type CancelToken = Symbol | string | number; + +export enum ContentType { + Json = "application/json", + FormData = "multipart/form-data", + UrlEncoded = "application/x-www-form-urlencoded", +} + +export class HttpClient { + public baseUrl: string = "https://ffff.com"; + private securityData: SecurityDataType | null = null; + private securityWorker?: ApiConfig["securityWorker"]; + private abortControllers = new Map(); + + private baseApiParams: RequestParams = { + credentials: "same-origin", + headers: {}, + redirect: "follow", + referrerPolicy: "no-referrer", + }; + + constructor(apiConfig: ApiConfig = {}) { + Object.assign(this, apiConfig); + } + + public setSecurityData = (data: SecurityDataType | null) => { + this.securityData = data; + }; + + private addQueryParam(query: QueryParamsType, key: string) { + const value = query[key]; + + return ( + encodeURIComponent(key) + + "=" + + encodeURIComponent(Array.isArray(value) ? value.join(",") : typeof value === "number" ? value : `${value}`) + ); + } + + protected toQueryString(rawQuery?: QueryParamsType): string { + const query = rawQuery || {}; + const keys = Object.keys(query).filter((key) => "undefined" !== typeof query[key]); + return keys + .map((key) => + typeof query[key] === "object" && !Array.isArray(query[key]) + ? this.toQueryString(query[key] as QueryParamsType) + : this.addQueryParam(query, key), + ) + .join("&"); + } + + protected addQueryParams(rawQuery?: QueryParamsType): string { + const queryString = this.toQueryString(rawQuery); + return queryString ? `?${queryString}` : ""; + } + + private contentFormatters: Record any> = { + [ContentType.Json]: (input: any) => + input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input, + [ContentType.FormData]: (input: any) => + Object.keys(input || {}).reduce((data, key) => { + data.append(key, input[key]); + return data; + }, new FormData()), + [ContentType.UrlEncoded]: (input: any) => this.toQueryString(input), + }; + + private mergeRequestParams(params1: RequestParams, params2?: RequestParams): RequestParams { + return { + ...this.baseApiParams, + ...params1, + ...(params2 || {}), + headers: { + ...(this.baseApiParams.headers || {}), + ...(params1.headers || {}), + ...((params2 && params2.headers) || {}), + }, + }; + } + + private createAbortSignal = (cancelToken: CancelToken): AbortSignal | undefined => { + if (this.abortControllers.has(cancelToken)) { + const abortController = this.abortControllers.get(cancelToken); + if (abortController) { + return abortController.signal; + } + return void 0; + } + + const abortController = new AbortController(); + this.abortControllers.set(cancelToken, abortController); + return abortController.signal; + }; + + public abortRequest = (cancelToken: CancelToken) => { + const abortController = this.abortControllers.get(cancelToken); + + if (abortController) { + abortController.abort(); + this.abortControllers.delete(cancelToken); + } + }; + + public request = async ({ + body, + secure, + path, + type, + query, + format = "json", + baseUrl, + cancelToken, + ...params + }: FullRequestParams): Promise> => { + const secureParams = (secure && this.securityWorker && (await this.securityWorker(this.securityData))) || {}; + const requestParams = this.mergeRequestParams(params, secureParams); + const queryString = query && this.toQueryString(query); + const payloadFormatter = this.contentFormatters[type || ContentType.Json]; + + return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { + ...requestParams, + headers: { + ...(type && type !== ContentType.FormData ? { "Content-Type": type } : {}), + ...(requestParams.headers || {}), + }, + signal: cancelToken ? this.createAbortSignal(cancelToken) : void 0, + body: typeof body === "undefined" || body === null ? null : payloadFormatter(body), + }).then(async (response) => { + const r = response as HttpResponse; + r.data = (null as unknown) as T; + r.error = (null as unknown) as E; + + const data = await response[format]() + .then((data) => { + if (r.ok) { + r.data = data; + } else { + r.error = data; + } + return r; + }) + .catch((e) => { + r.error = e; + return r; + }); + + if (cancelToken) { + this.abortControllers.delete(cancelToken); + } + + if (!response.ok) throw data; + return data; + }); + }; +} + +/** + * @title No title + * @baseUrl https://ffff.com + */ +export class Api extends HttpClient {} diff --git a/tests/generated/v2.0/example1.ts b/tests/generated/v2.0/example1.ts index 53e5a0ec..7ac00ab4 100644 --- a/tests/generated/v2.0/example1.ts +++ b/tests/generated/v2.0/example1.ts @@ -231,6 +231,7 @@ export class HttpClient { * @title SqlManagementClient * @version 2017-10-01-preview * @baseUrl https://management.azure.com + * * The Azure SQL Database management API provides a RESTful set of web APIs that interact with Azure SQL Database services to manage your databases. The API enables users to create, retrieve, update, and delete databases, servers, and other entities. */ export class Api extends HttpClient { diff --git a/tests/generated/v2.0/furkot-example.ts b/tests/generated/v2.0/furkot-example.ts index 39a287d8..e2b122fa 100644 --- a/tests/generated/v2.0/furkot-example.ts +++ b/tests/generated/v2.0/furkot-example.ts @@ -267,6 +267,9 @@ export class HttpClient { * @title Furkot Trips * @version 1.0.0 * @baseUrl https://trips.furkot.com/pub/api + * @externalDocs https://help.furkot.com/widgets/furkot-api.html + * @contact + * * Furkot provides Rest API to access user trip data. * Using Furkot API an application can list user trips and display stops for a specific trip. * Furkot API uses OAuth2 protocol to authorize applications to access data on behalf of users. diff --git a/tests/generated/v2.0/giphy.ts b/tests/generated/v2.0/giphy.ts index 75a66dfb..b827f548 100644 --- a/tests/generated/v2.0/giphy.ts +++ b/tests/generated/v2.0/giphy.ts @@ -46,26 +46,26 @@ export interface Gif { /** An object containing data for various available formats and sizes of this GIF. */ images?: { - downsized?: Image & any; - downsized_large?: Image & any; - downsized_medium?: Image & any; - downsized_small?: Image & any; - downsized_still?: Image & any; - fixed_height?: Image & any; - fixed_height_downsampled?: Image & any; - fixed_height_small?: Image & any; - fixed_height_small_still?: Image & any; - fixed_height_still?: Image & any; - fixed_width?: Image & any; - fixed_width_downsampled?: Image & any; - fixed_width_small?: Image & any; - fixed_width_small_still?: Image & any; - fixed_width_still?: Image & any; - looping?: Image & any; - original?: Image & any; - original_still?: Image & any; - preview?: Image & any; - preview_gif?: Image & any; + downsized?: Image; + downsized_large?: Image; + downsized_medium?: Image; + downsized_small?: Image; + downsized_still?: Image; + fixed_height?: Image; + fixed_height_downsampled?: Image; + fixed_height_small?: Image; + fixed_height_small_still?: Image; + fixed_height_still?: Image; + fixed_width?: Image; + fixed_width_downsampled?: Image; + fixed_width_small?: Image; + fixed_width_small_still?: Image; + fixed_width_still?: Image; + looping?: Image; + original?: Image; + original_still?: Image; + preview?: Image; + preview_gif?: Image; }; /** @@ -485,7 +485,11 @@ export class HttpClient { /** * @title Giphy * @version 1.0 + * @termsOfService https://developers.giphy.com/ * @baseUrl https://api.giphy.com/v1 + * @externalDocs https://developers.giphy.com/docs/ + * @contact + * * Giphy API */ export class Api extends HttpClient { diff --git a/tests/generated/v2.0/github-swagger.ts b/tests/generated/v2.0/github-swagger.ts index 1a332a9e..d2eb3884 100644 --- a/tests/generated/v2.0/github-swagger.ts +++ b/tests/generated/v2.0/github-swagger.ts @@ -763,7 +763,10 @@ export interface OrgTeamsPost { repo_names?: string[]; } -export type Organization = Actor & any; +/** + * A GitHub organization + */ +export type Organization = Actor; export interface OrganizationAsTeamMember { errors?: { code?: string; field?: string; resource?: string }[]; @@ -1114,13 +1117,17 @@ export interface Repo { /** A user or organization */ owner?: Actor; - parent?: Repo & any; + + /** Is present when the repo is a fork. Parent is the repo this repo was forked from. */ + parent?: Repo; private?: boolean; /** ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ */ pushed_at?: string; size?: number; - source?: Repo & any; + + /** Is present when the repo is a fork. Source is the ultimate source for the network. */ + source?: Repo; ssh_url?: string; svn_url?: string; @@ -1406,7 +1413,10 @@ export interface Trees { url?: string; } -export type User = Actor & any; +/** + * A GitHub user + */ +export type User = Actor; export type UserEmails = string[]; @@ -1628,7 +1638,10 @@ export class HttpClient { /** * @title GitHub * @version v3 + * @termsOfService https://help.github.com/articles/github-terms-of-service/#b-api-terms * @baseUrl https://api.github.com + * @externalDocs https://developer.github.com/v3/ + * * Powerful collaboration, code review, and code management for open source and private projects. */ export class Api extends HttpClient { diff --git a/tests/generated/v2.0/path-args.ts b/tests/generated/v2.0/path-args.ts index 1cb18822..f878acfd 100644 --- a/tests/generated/v2.0/path-args.ts +++ b/tests/generated/v2.0/path-args.ts @@ -203,6 +203,7 @@ export class HttpClient { /** * @title Path Args * @version 1.0.0 + * @license MIT * @baseUrl http://unknown.io/v666 */ export class Api extends HttpClient { diff --git a/tests/generated/v2.0/petstore-expanded.ts b/tests/generated/v2.0/petstore-expanded.ts index ffe605a1..63fb0eb0 100644 --- a/tests/generated/v2.0/petstore-expanded.ts +++ b/tests/generated/v2.0/petstore-expanded.ts @@ -240,7 +240,11 @@ export class HttpClient { /** * @title Swagger Petstore * @version 1.0.0 + * @license Apache 2.0 (https://www.apache.org/licenses/LICENSE-2.0.html) + * @termsOfService http://swagger.io/terms/ * @baseUrl http://petstore.swagger.io/api + * @contact Swagger API Team (http://swagger.io) + * * A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification */ export class Api extends HttpClient { diff --git a/tests/generated/v2.0/petstore-minimal.ts b/tests/generated/v2.0/petstore-minimal.ts index c540f15a..d0f92365 100644 --- a/tests/generated/v2.0/petstore-minimal.ts +++ b/tests/generated/v2.0/petstore-minimal.ts @@ -211,7 +211,11 @@ export class HttpClient { /** * @title Swagger Petstore * @version 1.0.0 + * @license MIT + * @termsOfService http://swagger.io/terms/ * @baseUrl http://petstore.swagger.io/api + * @contact Swagger API Team + * * A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification */ export class Api extends HttpClient { diff --git a/tests/generated/v2.0/petstore-simple.ts b/tests/generated/v2.0/petstore-simple.ts index 7a375209..49af40ba 100644 --- a/tests/generated/v2.0/petstore-simple.ts +++ b/tests/generated/v2.0/petstore-simple.ts @@ -226,7 +226,11 @@ export class HttpClient { /** * @title Swagger Petstore * @version 1.0.0 + * @license MIT + * @termsOfService http://swagger.io/terms/ * @baseUrl http://petstore.swagger.io/api + * @contact Swagger API Team + * * A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification */ export class Api extends HttpClient { diff --git a/tests/generated/v2.0/petstore-swagger-io.ts b/tests/generated/v2.0/petstore-swagger-io.ts index 4deaef71..6a8523c6 100644 --- a/tests/generated/v2.0/petstore-swagger-io.ts +++ b/tests/generated/v2.0/petstore-swagger-io.ts @@ -271,7 +271,12 @@ export class HttpClient { /** * @title Swagger Petstore * @version 1.0.3 + * @license Apache 2.0 (http://www.apache.org/licenses/LICENSE-2.0.html) + * @termsOfService http://swagger.io/terms/ * @baseUrl https://petstore.swagger.io/v2 + * @externalDocs http://swagger.io + * @contact + * * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. */ export class Api extends HttpClient { diff --git a/tests/generated/v2.0/petstore-with-external-docs.ts b/tests/generated/v2.0/petstore-with-external-docs.ts index f62db355..9a6766ed 100644 --- a/tests/generated/v2.0/petstore-with-external-docs.ts +++ b/tests/generated/v2.0/petstore-with-external-docs.ts @@ -216,7 +216,12 @@ export class HttpClient { /** * @title Swagger Petstore * @version 1.0.0 + * @license Apache 2.0 (https://www.apache.org/licenses/LICENSE-2.0.html) + * @termsOfService http://swagger.io/terms/ * @baseUrl http://petstore.swagger.io/api + * @externalDocs https://swagger.io/about + * @contact Swagger API Team (http://swagger.io) + * * A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification */ export class Api extends HttpClient { diff --git a/tests/generated/v2.0/petstore.ts b/tests/generated/v2.0/petstore.ts index 5b7b7c87..3ffbff74 100644 --- a/tests/generated/v2.0/petstore.ts +++ b/tests/generated/v2.0/petstore.ts @@ -218,6 +218,7 @@ export class HttpClient { /** * @title Swagger Petstore * @version 1.0.0 + * @license MIT * @baseUrl http://petstore.swagger.io/v1 */ export class Api extends HttpClient { diff --git a/tests/generated/v2.0/query-path-param.ts b/tests/generated/v2.0/query-path-param.ts index 2e0e05bc..1451e461 100644 --- a/tests/generated/v2.0/query-path-param.ts +++ b/tests/generated/v2.0/query-path-param.ts @@ -203,6 +203,7 @@ export class HttpClient { /** * @title Query Path Param * @version 1.0.0 + * @license MIT * @baseUrl http://unknown.io/v666 */ export class Api extends HttpClient { diff --git a/tests/generated/v2.0/uber.ts b/tests/generated/v2.0/uber.ts index 94f462b4..18783cac 100644 --- a/tests/generated/v2.0/uber.ts +++ b/tests/generated/v2.0/uber.ts @@ -299,6 +299,7 @@ export class HttpClient { * @title Uber API * @version 1.0.0 * @baseUrl https://api.uber.com/v1 + * * Move your app forward with the Uber API */ export class Api extends HttpClient { diff --git a/tests/generated/v3.0/components-responses.ts b/tests/generated/v3.0/components-responses.ts index 03555e97..95d2c261 100644 --- a/tests/generated/v3.0/components-responses.ts +++ b/tests/generated/v3.0/components-responses.ts @@ -203,6 +203,7 @@ export class HttpClient { /** * @title Title * @version latest + * * Description */ export class Api extends HttpClient { diff --git a/tests/generated/v3.0/explode-param-3.0.1.ts b/tests/generated/v3.0/explode-param-3.0.1.ts index 8b45aa66..46a96699 100644 --- a/tests/generated/v3.0/explode-param-3.0.1.ts +++ b/tests/generated/v3.0/explode-param-3.0.1.ts @@ -219,6 +219,7 @@ export class HttpClient { /** * @title API * @version 0.1 + * * Documentation */ export class Api extends HttpClient { diff --git a/tests/generated/v3.0/full-swagger-scheme.ts b/tests/generated/v3.0/full-swagger-scheme.ts index 93f59d7b..6140566f 100644 --- a/tests/generated/v3.0/full-swagger-scheme.ts +++ b/tests/generated/v3.0/full-swagger-scheme.ts @@ -9147,7 +9147,12 @@ export class HttpClient { /** * @title GitHub v3 REST API * @version 1.1.4 + * @license MIT (https://spdx.org/licenses/MIT) + * @termsOfService https://docs.github.com/articles/github-terms-of-service * @baseUrl https://api.github.com + * @externalDocs https://docs.github.com/rest/ + * @contact Support (https://support.github.com/contact) + * * GitHub's v3 REST API. */ export class Api extends HttpClient { @@ -10600,12 +10605,9 @@ export class Api extends HttpClient; + files?: Record; }, params: RequestParams = {}, ) => diff --git a/tests/generated/v3.0/petstore-expanded.ts b/tests/generated/v3.0/petstore-expanded.ts index c5e3c7b2..e64423d5 100644 --- a/tests/generated/v3.0/petstore-expanded.ts +++ b/tests/generated/v3.0/petstore-expanded.ts @@ -216,7 +216,11 @@ export class HttpClient { /** * @title Swagger Petstore * @version 1.0.0 + * @license Apache 2.0 (https://www.apache.org/licenses/LICENSE-2.0.html) + * @termsOfService http://swagger.io/terms/ * @baseUrl http://petstore.swagger.io/api + * @contact Swagger API Team (http://swagger.io) + * * A sample API that uses a petstore as an example to demonstrate features in the OpenAPI 3.0 specification */ export class Api extends HttpClient { diff --git a/tests/generated/v3.0/petstore.ts b/tests/generated/v3.0/petstore.ts index aefcc740..caa1fc99 100644 --- a/tests/generated/v3.0/petstore.ts +++ b/tests/generated/v3.0/petstore.ts @@ -220,6 +220,7 @@ export class HttpClient { /** * @title Swagger Petstore * @version 1.0.0 + * @license MIT * @baseUrl http://petstore.swagger.io/v1 */ export class Api extends HttpClient { diff --git a/tests/generated/v3.0/responses.ts b/tests/generated/v3.0/responses.ts index 605a9662..bca13593 100644 --- a/tests/generated/v3.0/responses.ts +++ b/tests/generated/v3.0/responses.ts @@ -203,6 +203,7 @@ export class HttpClient { /** * @title Title * @version latest + * * Description */ export class Api extends HttpClient { diff --git a/tests/generated/v3.0/swaggerhub-template.ts b/tests/generated/v3.0/swaggerhub-template.ts index 7c5fa187..63920444 100644 --- a/tests/generated/v3.0/swaggerhub-template.ts +++ b/tests/generated/v3.0/swaggerhub-template.ts @@ -204,6 +204,7 @@ export class HttpClient { * @title Sample Application Flow OAuth2 Project * @version 1.0.0 * @baseUrl https://virtserver.swaggerhub.com/sdfsdfsffs/sdfff/1.0.0 + * * This is an example of using OAuth2 Application Flow in a specification to describe security to your API. */ export class Api extends HttpClient { diff --git a/tests/generated/v3.0/up-banking.ts b/tests/generated/v3.0/up-banking.ts index 385e5366..d16ab572 100644 --- a/tests/generated/v3.0/up-banking.ts +++ b/tests/generated/v3.0/up-banking.ts @@ -732,6 +732,8 @@ export class HttpClient { * @title Up API * @version v1 * @baseUrl https://api.up.com.au/api/v1 + * @contact API Specification and Support (https://github.com/up-banking/api) + * * The Up API gives you programmatic access to your balances and * transaction data. You can request past transactions or set up * webhooks to receive real-time events when new transactions hit your diff --git a/tests/generated/v3.0/uspto.ts b/tests/generated/v3.0/uspto.ts index 35b769ee..2424e79b 100644 --- a/tests/generated/v3.0/uspto.ts +++ b/tests/generated/v3.0/uspto.ts @@ -221,6 +221,8 @@ export class HttpClient { * @title USPTO Data Set API * @version 1.0.0 * @baseUrl {scheme}://developer.uspto.gov/ds-api + * @contact Open Data Portal (https://developer.uspto.gov) + * * The Data Set API (DSAPI) allows the public users to discover and search USPTO exported data sets. This is a generic API that allows USPTO users to make any CSV based data files searchable through API. With the help of GET call, it returns the list of data fields that are searchable. With the help of POST call, data can be fetched based on the filters on the field names. Please note that POST call is used to search the actual data. The reason for the POST call is that it allows users to specify any complex search criteria without worry about the GET size limitations as well as encoding of the input parameters. */ export class Api extends HttpClient { diff --git a/tests/schemas/v2.0/enums.json b/tests/schemas/v2.0/enums.json new file mode 100644 index 00000000..f551f550 --- /dev/null +++ b/tests/schemas/v2.0/enums.json @@ -0,0 +1,61 @@ +{ + "swagger": "2.0", + "schemes": ["https"], + "host": "ffff.com", + "basePath": "/", + "info": {}, + "definitions": { + "OnlyEnumNames": { + "x-enumNames": ["Bla", "Blabla", "Boiler"] + }, + "StringOnlyEnumNames": { + "type": "int32", + "x-enumNames": ["Bla", "Blabla", "Boiler"] + }, + "StringEnums": { + "type": "int32", + "enum": ["foo", "bar"], + "x-enumNames": ["Bla", "Blabla", "Boiler"] + }, + "StringCompleteEnums": { + "type": "int32", + "enum": ["foo", "bar", "baz"], + "x-enumNames": ["Bla", "Blabla", "Boiler"] + }, + "EmptyEnum": { + "format": "int32", + "type": "integer", + "x-enumNames": ["Bla", "Blabla", "Boiler"] + }, + "EnumWithMoreNames": { + "format": "int32", + "type": "integer", + "enum": [1], + "x-enumNames": ["Bla", "Blabla", "Boiler"] + }, + "SomeInterestEnum": { + "format": "int32", + "enum": [6, 2, 1, 67, 88, 122, 88, 0, 213, 12378, 123125, 32452, 1111, 66666], + "type": "integer", + "x-enumNames": [ + "Bla", + "Blabla", + "Boiler", + "Bbabab", + "Nowadays", + "FAIL", + "Vvvvv", + "ASdasAS", + "ASDsacZX", + "Zook", + "EnumMm", + "VCsa", + "Yuuu", + "ASddd", + "ASdsdsa", + "ASDds", + "HSDFDS" + ] + } + } +} diff --git a/tests/spec/axios/schema.ts b/tests/spec/axios/schema.ts index 0f7aa413..ac8d6005 100644 --- a/tests/spec/axios/schema.ts +++ b/tests/spec/axios/schema.ts @@ -763,7 +763,10 @@ export interface OrgTeamsPost { repo_names?: string[]; } -export type Organization = Actor & any; +/** + * A GitHub organization + */ +export type Organization = Actor; export interface OrganizationAsTeamMember { errors?: { code?: string; field?: string; resource?: string }[]; @@ -1114,13 +1117,17 @@ export interface Repo { /** A user or organization */ owner?: Actor; - parent?: Repo & any; + + /** Is present when the repo is a fork. Parent is the repo this repo was forked from. */ + parent?: Repo; private?: boolean; /** ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ */ pushed_at?: string; size?: number; - source?: Repo & any; + + /** Is present when the repo is a fork. Source is the ultimate source for the network. */ + source?: Repo; ssh_url?: string; svn_url?: string; @@ -1406,7 +1413,10 @@ export interface Trees { url?: string; } -export type User = Actor & any; +/** + * A GitHub user + */ +export type User = Actor; export type UserEmails = string[]; @@ -1523,7 +1533,10 @@ export class HttpClient { /** * @title GitHub * @version v3 + * @termsOfService https://help.github.com/articles/github-terms-of-service/#b-api-terms * @baseUrl https://api.github.com + * @externalDocs https://developer.github.com/v3/ + * * Powerful collaboration, code review, and code management for open source and private projects. */ export class Api extends HttpClient { diff --git a/tests/spec/axiosSingleHttpClient/schema.ts b/tests/spec/axiosSingleHttpClient/schema.ts index f5e7d8c1..d67742da 100644 --- a/tests/spec/axiosSingleHttpClient/schema.ts +++ b/tests/spec/axiosSingleHttpClient/schema.ts @@ -763,7 +763,10 @@ export interface OrgTeamsPost { repo_names?: string[]; } -export type Organization = Actor & any; +/** + * A GitHub organization + */ +export type Organization = Actor; export interface OrganizationAsTeamMember { errors?: { code?: string; field?: string; resource?: string }[]; @@ -1114,13 +1117,17 @@ export interface Repo { /** A user or organization */ owner?: Actor; - parent?: Repo & any; + + /** Is present when the repo is a fork. Parent is the repo this repo was forked from. */ + parent?: Repo; private?: boolean; /** ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ */ pushed_at?: string; size?: number; - source?: Repo & any; + + /** Is present when the repo is a fork. Source is the ultimate source for the network. */ + source?: Repo; ssh_url?: string; svn_url?: string; @@ -1406,7 +1413,10 @@ export interface Trees { url?: string; } -export type User = Actor & any; +/** + * A GitHub user + */ +export type User = Actor; export type UserEmails = string[]; @@ -1523,7 +1533,10 @@ export class HttpClient { /** * @title GitHub * @version v3 + * @termsOfService https://help.github.com/articles/github-terms-of-service/#b-api-terms * @baseUrl https://api.github.com + * @externalDocs https://developer.github.com/v3/ + * * Powerful collaboration, code review, and code management for open source and private projects. */ export class Api { diff --git a/tests/spec/defaultAsSuccess/schema.ts b/tests/spec/defaultAsSuccess/schema.ts index 94424154..a8a3635f 100644 --- a/tests/spec/defaultAsSuccess/schema.ts +++ b/tests/spec/defaultAsSuccess/schema.ts @@ -255,7 +255,11 @@ export class HttpClient { /** * @title Authentiq * @version 6 + * @license Apache 2.0 (http://www.apache.org/licenses/LICENSE-2.0.html) + * @termsOfService http://authentiq.com/terms/ * @baseUrl https://6-dot-authentiqio.appspot.com + * @contact Authentiq team (http://authentiq.io/support) + * * Strong authentication, without the passwords. */ export class Api extends HttpClient { diff --git a/tests/spec/defaultResponse/schema.ts b/tests/spec/defaultResponse/schema.ts index 034a3950..1bf5a662 100644 --- a/tests/spec/defaultResponse/schema.ts +++ b/tests/spec/defaultResponse/schema.ts @@ -203,7 +203,11 @@ export class HttpClient { /** * @title Swagger Petstore * @version 1.0.0 + * @license Apache 2.0 (https://www.apache.org/licenses/LICENSE-2.0.html) + * @termsOfService http://swagger.io/terms/ * @baseUrl http://petstore.swagger.io/api + * @contact Swagger API Team (http://swagger.io) + * * A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification */ export class Api extends HttpClient { diff --git a/tests/spec/extractRequestParams/schema.ts b/tests/spec/extractRequestParams/schema.ts index f9f5cf99..78d151e9 100644 --- a/tests/spec/extractRequestParams/schema.ts +++ b/tests/spec/extractRequestParams/schema.ts @@ -295,7 +295,11 @@ export class HttpClient { /** * @title Authentiq * @version 6 + * @license Apache 2.0 (http://www.apache.org/licenses/LICENSE-2.0.html) + * @termsOfService http://authentiq.com/terms/ * @baseUrl https://6-dot-authentiqio.appspot.com + * @contact Authentiq team (http://authentiq.io/support) + * * Strong authentication, without the passwords. */ export class Api extends HttpClient { diff --git a/tests/spec/js/schema.d.ts b/tests/spec/js/schema.d.ts index dd33e048..207daa47 100644 --- a/tests/spec/js/schema.d.ts +++ b/tests/spec/js/schema.d.ts @@ -929,7 +929,10 @@ export interface OrgTeamsPost { permission?: "pull" | "push" | "admin"; repo_names?: string[]; } -export declare type Organization = Actor & any; +/** + * A GitHub organization + */ +export declare type Organization = Actor; export interface OrganizationAsTeamMember { errors?: { code?: string; @@ -1367,12 +1370,14 @@ export interface Repo { organization?: Organization; /** A user or organization */ owner?: Actor; - parent?: Repo & any; + /** Is present when the repo is a fork. Parent is the repo this repo was forked from. */ + parent?: Repo; private?: boolean; /** ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ */ pushed_at?: string; size?: number; - source?: Repo & any; + /** Is present when the repo is a fork. Source is the ultimate source for the network. */ + source?: Repo; ssh_url?: string; svn_url?: string; /** ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ */ @@ -1672,7 +1677,10 @@ export interface Trees { tree?: Tree[]; url?: string; } -export declare type User = Actor & any; +/** + * A GitHub user + */ +export declare type User = Actor; export declare type UserEmails = string[]; export interface UserKeysKeyId { id?: number; @@ -1760,7 +1768,10 @@ export declare class HttpClient { /** * @title GitHub * @version v3 + * @termsOfService https://help.github.com/articles/github-terms-of-service/#b-api-terms * @baseUrl https://api.github.com + * @externalDocs https://developer.github.com/v3/ + * * Powerful collaboration, code review, and code management for open source and private projects. */ export declare class Api extends HttpClient { diff --git a/tests/spec/js/schema.js b/tests/spec/js/schema.js index c188fd79..c20cf10e 100644 --- a/tests/spec/js/schema.js +++ b/tests/spec/js/schema.js @@ -136,7 +136,10 @@ export class HttpClient { /** * @title GitHub * @version v3 + * @termsOfService https://help.github.com/articles/github-terms-of-service/#b-api-terms * @baseUrl https://api.github.com + * @externalDocs https://developer.github.com/v3/ + * * Powerful collaboration, code review, and code management for open source and private projects. */ export class Api extends HttpClient { diff --git a/tests/spec/jsAxios/schema.d.ts b/tests/spec/jsAxios/schema.d.ts index 83054bda..cce23654 100644 --- a/tests/spec/jsAxios/schema.d.ts +++ b/tests/spec/jsAxios/schema.d.ts @@ -929,7 +929,10 @@ export interface OrgTeamsPost { permission?: "pull" | "push" | "admin"; repo_names?: string[]; } -export declare type Organization = Actor & any; +/** + * A GitHub organization + */ +export declare type Organization = Actor; export interface OrganizationAsTeamMember { errors?: { code?: string; @@ -1367,12 +1370,14 @@ export interface Repo { organization?: Organization; /** A user or organization */ owner?: Actor; - parent?: Repo & any; + /** Is present when the repo is a fork. Parent is the repo this repo was forked from. */ + parent?: Repo; private?: boolean; /** ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ */ pushed_at?: string; size?: number; - source?: Repo & any; + /** Is present when the repo is a fork. Source is the ultimate source for the network. */ + source?: Repo; ssh_url?: string; svn_url?: string; /** ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ */ @@ -1672,7 +1677,10 @@ export interface Trees { tree?: Tree[]; url?: string; } -export declare type User = Actor & any; +/** + * A GitHub user + */ +export declare type User = Actor; export declare type UserEmails = string[]; export interface UserKeysKeyId { id?: number; @@ -1741,7 +1749,10 @@ export declare class HttpClient { /** * @title GitHub * @version v3 + * @termsOfService https://help.github.com/articles/github-terms-of-service/#b-api-terms * @baseUrl https://api.github.com + * @externalDocs https://developer.github.com/v3/ + * * Powerful collaboration, code review, and code management for open source and private projects. */ export declare class Api extends HttpClient { diff --git a/tests/spec/jsAxios/schema.js b/tests/spec/jsAxios/schema.js index 31a9c120..7ef0590b 100644 --- a/tests/spec/jsAxios/schema.js +++ b/tests/spec/jsAxios/schema.js @@ -56,7 +56,10 @@ export class HttpClient { /** * @title GitHub * @version v3 + * @termsOfService https://help.github.com/articles/github-terms-of-service/#b-api-terms * @baseUrl https://api.github.com + * @externalDocs https://developer.github.com/v3/ + * * Powerful collaboration, code review, and code management for open source and private projects. */ export class Api extends HttpClient { diff --git a/tests/spec/moduleNameFirstTag/schema.ts b/tests/spec/moduleNameFirstTag/schema.ts index a912e482..56044c70 100644 --- a/tests/spec/moduleNameFirstTag/schema.ts +++ b/tests/spec/moduleNameFirstTag/schema.ts @@ -331,7 +331,12 @@ export class HttpClient { /** * @title Swagger Petstore * @version 1.0.0 + * @license Apache-2.0 (http://www.apache.org/licenses/LICENSE-2.0.html) + * @termsOfService http://swagger.io/terms/ * @baseUrl http://petstore.swagger.io/v2 + * @externalDocs http://swagger.io + * @contact + * * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. */ export class Api extends HttpClient { diff --git a/tests/spec/moduleNameIndex/schema.ts b/tests/spec/moduleNameIndex/schema.ts index edf1eb39..9ae85604 100644 --- a/tests/spec/moduleNameIndex/schema.ts +++ b/tests/spec/moduleNameIndex/schema.ts @@ -331,7 +331,12 @@ export class HttpClient { /** * @title Swagger Petstore * @version 1.0.0 + * @license Apache-2.0 (http://www.apache.org/licenses/LICENSE-2.0.html) + * @termsOfService http://swagger.io/terms/ * @baseUrl http://petstore.swagger.io/v2 + * @externalDocs http://swagger.io + * @contact + * * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. */ export class Api extends HttpClient { diff --git a/tests/spec/noClient/schema.ts b/tests/spec/noClient/schema.ts index db2f2797..e6ca5875 100644 --- a/tests/spec/noClient/schema.ts +++ b/tests/spec/noClient/schema.ts @@ -763,7 +763,10 @@ export interface OrgTeamsPost { repo_names?: string[]; } -export type Organization = Actor & any; +/** + * A GitHub organization + */ +export type Organization = Actor; export interface OrganizationAsTeamMember { errors?: { code?: string; field?: string; resource?: string }[]; @@ -1114,13 +1117,17 @@ export interface Repo { /** A user or organization */ owner?: Actor; - parent?: Repo & any; + + /** Is present when the repo is a fork. Parent is the repo this repo was forked from. */ + parent?: Repo; private?: boolean; /** ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ */ pushed_at?: string; size?: number; - source?: Repo & any; + + /** Is present when the repo is a fork. Source is the ultimate source for the network. */ + source?: Repo; ssh_url?: string; svn_url?: string; @@ -1406,7 +1413,10 @@ export interface Trees { url?: string; } -export type User = Actor & any; +/** + * A GitHub user + */ +export type User = Actor; export type UserEmails = string[]; diff --git a/tests/spec/partialBaseTemplate/schema.ts b/tests/spec/partialBaseTemplate/schema.ts index 742d27f3..0940299c 100644 --- a/tests/spec/partialBaseTemplate/schema.ts +++ b/tests/spec/partialBaseTemplate/schema.ts @@ -215,7 +215,11 @@ export class HttpClient { /** * @title Swagger Petstore * @version 1.0.0 + * @license MIT + * @termsOfService http://swagger.io/terms/ * @baseUrl http://petstore.swagger.io/api + * @contact Swagger API Team + * * A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification */ export class Api extends HttpClient { diff --git a/tests/spec/responses/schema.ts b/tests/spec/responses/schema.ts index 02791575..96255485 100644 --- a/tests/spec/responses/schema.ts +++ b/tests/spec/responses/schema.ts @@ -255,7 +255,11 @@ export class HttpClient { /** * @title Authentiq * @version 6 + * @license Apache 2.0 (http://www.apache.org/licenses/LICENSE-2.0.html) + * @termsOfService http://authentiq.com/terms/ * @baseUrl https://6-dot-authentiqio.appspot.com + * @contact Authentiq team (http://authentiq.io/support) + * * Strong authentication, without the passwords. */ export class Api extends HttpClient { diff --git a/tests/spec/routeTypes/schema.ts b/tests/spec/routeTypes/schema.ts index b785631f..c43376ac 100644 --- a/tests/spec/routeTypes/schema.ts +++ b/tests/spec/routeTypes/schema.ts @@ -763,7 +763,10 @@ export interface OrgTeamsPost { repo_names?: string[]; } -export type Organization = Actor & any; +/** + * A GitHub organization + */ +export type Organization = Actor; export interface OrganizationAsTeamMember { errors?: { code?: string; field?: string; resource?: string }[]; @@ -1114,13 +1117,17 @@ export interface Repo { /** A user or organization */ owner?: Actor; - parent?: Repo & any; + + /** Is present when the repo is a fork. Parent is the repo this repo was forked from. */ + parent?: Repo; private?: boolean; /** ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ */ pushed_at?: string; size?: number; - source?: Repo & any; + + /** Is present when the repo is a fork. Source is the ultimate source for the network. */ + source?: Repo; ssh_url?: string; svn_url?: string; @@ -1406,7 +1413,10 @@ export interface Trees { url?: string; } -export type User = Actor & any; +/** + * A GitHub user + */ +export type User = Actor; export type UserEmails = string[]; diff --git a/tests/spec/singleHttpClient/schema.ts b/tests/spec/singleHttpClient/schema.ts index 41d74b7b..c0236b10 100644 --- a/tests/spec/singleHttpClient/schema.ts +++ b/tests/spec/singleHttpClient/schema.ts @@ -203,7 +203,11 @@ export class HttpClient { /** * @title Authentiq * @version 6 + * @license Apache 2.0 (http://www.apache.org/licenses/LICENSE-2.0.html) + * @termsOfService http://authentiq.com/terms/ * @baseUrl https://6-dot-authentiqio.appspot.com + * @contact Authentiq team (http://authentiq.io/support) + * * Strong authentication, without the passwords. */ export class Api { diff --git a/tests/spec/typeSuffixPrefix/schema.ts b/tests/spec/typeSuffixPrefix/schema.ts index 7fb84e51..daca55a1 100644 --- a/tests/spec/typeSuffixPrefix/schema.ts +++ b/tests/spec/typeSuffixPrefix/schema.ts @@ -769,7 +769,10 @@ export interface SwaggerTypeOrgTeamsPostGeneratedDataContract { repo_names?: string[]; } -export type SwaggerTypeOrganizationGeneratedDataContract = SwaggerTypeActorGeneratedDataContract & any; +/** + * A GitHub organization + */ +export type SwaggerTypeOrganizationGeneratedDataContract = SwaggerTypeActorGeneratedDataContract; export interface SwaggerTypeOrganizationAsTeamMemberGeneratedDataContract { errors?: { code?: string; field?: string; resource?: string }[]; @@ -1124,13 +1127,17 @@ export interface SwaggerTypeRepoGeneratedDataContract { /** A user or organization */ owner?: SwaggerTypeActorGeneratedDataContract; - parent?: SwaggerTypeRepoGeneratedDataContract & any; + + /** Is present when the repo is a fork. Parent is the repo this repo was forked from. */ + parent?: SwaggerTypeRepoGeneratedDataContract; private?: boolean; /** ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ */ pushed_at?: string; size?: number; - source?: SwaggerTypeRepoGeneratedDataContract & any; + + /** Is present when the repo is a fork. Source is the ultimate source for the network. */ + source?: SwaggerTypeRepoGeneratedDataContract; ssh_url?: string; svn_url?: string; @@ -1416,7 +1423,10 @@ export interface SwaggerTypeTreesGeneratedDataContract { url?: string; } -export type SwaggerTypeUserGeneratedDataContract = SwaggerTypeActorGeneratedDataContract & any; +/** + * A GitHub user + */ +export type SwaggerTypeUserGeneratedDataContract = SwaggerTypeActorGeneratedDataContract; export type SwaggerTypeUserEmailsGeneratedDataContract = string[]; @@ -1638,7 +1648,10 @@ export class HttpClient { /** * @title GitHub * @version v3 + * @termsOfService https://help.github.com/articles/github-terms-of-service/#b-api-terms * @baseUrl https://api.github.com + * @externalDocs https://developer.github.com/v3/ + * * Powerful collaboration, code review, and code management for open source and private projects. */ export class Api extends HttpClient {