diff --git a/lib/__snapshots__/batch-convert.spec.ts.snap b/lib/__snapshots__/batch-convert.spec.ts.snap index 8876f7a..592e9f4 100644 --- a/lib/__snapshots__/batch-convert.spec.ts.snap +++ b/lib/__snapshots__/batch-convert.spec.ts.snap @@ -8,25 +8,31 @@ Object { "additionalProperties": false, "properties": Object { "bar": Object { + "title": "Foo.bar", "type": "string", }, "baz": Object { "anyOf": Array [ Object { + "title": "Foo.baz", "type": "number", }, Object { "$ref": "#/definitions/Foo", + "title": "Foo.baz", }, ], - "description": "@see baz documentation at http://documentation.yada", - "title": "A baz is a number of another Foo", + "description": "A baz is a number of another Foo + +@see baz documentation at http://documentation.yada", + "title": "Foo.baz", }, }, "required": Array [ "bar", "baz", ], + "title": "Foo", "type": "object", }, "Foo2": Object { @@ -36,12 +42,14 @@ Object { "items": Object { "type": "boolean", }, + "title": "Foo2.bak", "type": "array", }, }, "required": Array [ "bak", ], + "title": "Foo2", "type": "object", }, }, @@ -56,12 +64,14 @@ Object { "additionalProperties": false, "properties": Object { "name": Object { + "title": "SubDirType.name", "type": "string", }, }, "required": Array [ "name", ], + "title": "SubDirType", "type": "object", }, }, @@ -76,25 +86,31 @@ Object { "additionalProperties": false, "properties": Object { "bar": Object { + "title": "Foo.bar", "type": "string", }, "baz": Object { "anyOf": Array [ Object { + "title": "Foo.baz", "type": "number", }, Object { "$ref": "#/definitions/Foo", + "title": "Foo.baz", }, ], - "description": "@see baz documentation at http://documentation.yada", - "title": "A baz is a number of another Foo", + "description": "A baz is a number of another Foo + +@see baz documentation at http://documentation.yada", + "title": "Foo.baz", }, }, "required": Array [ "bar", "baz", ], + "title": "Foo", "type": "object", }, "Foo2": Object { @@ -104,12 +120,14 @@ Object { "items": Object { "type": "boolean", }, + "title": "Foo2.bak", "type": "array", }, }, "required": Array [ "bak", ], + "title": "Foo2", "type": "object", }, }, @@ -124,12 +142,14 @@ Object { "additionalProperties": false, "properties": Object { "name": Object { + "title": "SubDirType.name", "type": "string", }, }, "required": Array [ "name", ], + "title": "SubDirType", "type": "object", }, }, @@ -156,12 +176,14 @@ Object { "additionalProperties": false, "properties": Object { "name": Object { + "title": "SubDirType.name", "type": "string", }, }, "required": Array [ "name", ], + "title": "SubDirType", "type": "object", }, }, @@ -176,25 +198,31 @@ Object { "additionalProperties": false, "properties": Object { "bar": Object { + "title": "Foo.bar", "type": "string", }, "baz": Object { "anyOf": Array [ Object { + "title": "Foo.baz", "type": "number", }, Object { "$ref": "#/definitions/Foo", + "title": "Foo.baz", }, ], - "description": "@see baz documentation at http://documentation.yada", - "title": "A baz is a number of another Foo", + "description": "A baz is a number of another Foo + +@see baz documentation at http://documentation.yada", + "title": "Foo.baz", }, }, "required": Array [ "bar", "baz", ], + "title": "Foo", "type": "object", }, "Foo2": Object { @@ -204,12 +232,14 @@ Object { "items": Object { "type": "boolean", }, + "title": "Foo2.bak", "type": "array", }, }, "required": Array [ "bak", ], + "title": "Foo2", "type": "object", }, }, diff --git a/lib/__snapshots__/converter.spec.ts.snap b/lib/__snapshots__/converter.spec.ts.snap index fd70a43..970e9fc 100644 --- a/lib/__snapshots__/converter.spec.ts.snap +++ b/lib/__snapshots__/converter.spec.ts.snap @@ -20,15 +20,19 @@ import { suretype, v, compile, annotate } from 'suretype'; /** The validation schema for a Foo */ export const schemaFoo = suretype({ name: \\"Foo\\", - title: \\"The Foo type\\" + title: \\"Foo\\", + description: \\"The Foo type\\" }, v.object({ int: annotate({ - title: \\"This is the integer thing\\", - description: \\"@default 55\\" + title: \\"Foo.int\\", + description: \\"This is the integer thing\\\\n\\\\n@default 55\\" }, v.number().integer()), - str: v.string().required(), + str: annotate({ + title: \\"Foo.str\\" + }, v.string().required()), stra: annotate({ - title: \\"Excellent array of strings\\" + title: \\"Foo.stra\\", + description: \\"Excellent array of strings\\" }, v.array(v.string()).required()) })); @@ -83,7 +87,7 @@ paths: {} components: schemas: Foo: - title: This is Foo + description: This is Foo properties: gt5: exclusiveMinimum: 5 diff --git a/lib/convert-graphql.spec.ts b/lib/convert-graphql.spec.ts index 243eab0..66746ee 100644 --- a/lib/convert-graphql.spec.ts +++ b/lib/convert-graphql.spec.ts @@ -31,13 +31,15 @@ describe( "convert-graphql", ( ) => types: [ { name: 'Foo', - title: 'Foo type', + title: 'Foo', + description: 'Foo type', type: 'object', loc: expect.anything( ), properties: { bar: { node: { type: 'string', + title: 'Foo.bar', loc: expect.anything( ), }, required: true, @@ -45,6 +47,7 @@ describe( "convert-graphql", ( ) => num: { node: { type: 'number', + title: 'Foo.num', loc: expect.anything( ), }, required: false, @@ -52,6 +55,7 @@ describe( "convert-graphql", ( ) => int: { node: { type: 'integer', + title: 'Foo.int', loc: expect.anything( ), }, required: false, @@ -81,7 +85,8 @@ describe( "convert-graphql", ( ) => types: [ { name: 'Foo', - title: 'Foo type', + title: 'Foo', + description: 'Foo type', type: 'object', properties: { bar: { diff --git a/lib/fixtures/validator.st.ts b/lib/fixtures/validator.st.ts index 52cbd32..b2328f2 100644 --- a/lib/fixtures/validator.st.ts +++ b/lib/fixtures/validator.st.ts @@ -1,7 +1,7 @@ import { suretype, v } from 'suretype' export const myval = suretype( - { name: 'Foo', title: 'This is Foo' }, + { name: 'Foo', description: 'This is Foo' }, v.object( { gt5: v.number( ).gt( 5 ), gte5: v.number( ).gte( 5 ), diff --git a/lib/index.spec.ts b/lib/index.spec.ts index 63832d1..f84a185 100644 --- a/lib/index.spec.ts +++ b/lib/index.spec.ts @@ -20,7 +20,7 @@ describe( "index", ( ) => expect( JSON.parse( data ) ).toStrictEqual( { $comment: expect.anything( ), definitions: { - Foo: { type: [ 'number', 'string' ] }, + Foo: { type: [ 'number', 'string' ], title: 'Foo' }, }, } ); } ); diff --git a/lib/tests/__snapshots__/ts-to-openapi.test.ts.snap b/lib/tests/__snapshots__/ts-to-openapi.test.ts.snap index cb3951b..79bca33 100644 --- a/lib/tests/__snapshots__/ts-to-openapi.test.ts.snap +++ b/lib/tests/__snapshots__/ts-to-openapi.test.ts.snap @@ -1,5 +1,36 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`ts-to-openapi ensure descriptions are forwarded 1`] = ` +"openapi: 3.0.0 +info: + title: My API + version: v1 + x-comment: >- + Generated by core-types-json-schema + (https://github.com/grantila/core-types-json-schema) on behalf of typeconv + (https://github.com/grantila/typeconv) +paths: {} +components: + schemas: + Point: + properties: + x: + title: Point.x + description: The distance from the left in mm + type: number + 'y': + title: Point.y + description: The distance from the top in mm + type: number + required: + - x + - 'y' + additionalProperties: false + title: Point + type: object +" +`; + exports[`ts-to-openapi typescript to openapi 1`] = ` "openapi: 3.0.0 info: @@ -15,15 +46,20 @@ components: Foo: properties: a: + title: Foo.a type: string b: + title: Foo.b nullable: true c: + title: Foo.c type: number d: + title: Foo.d type: boolean e: $ref: '#/components/schemas/Thing' + title: Foo.e required: - a - b @@ -31,47 +67,23 @@ components: - d - e additionalProperties: false + title: Foo type: object Thing: properties: x: + title: Thing.x enum: - 6 type: number 'y': + title: Thing.y type: string required: - x - 'y' additionalProperties: false - type: object -" -`; - -exports[`ts-to-openapi typescript to openapi 2`] = ` -"openapi: 3.0.0 -info: - title: My API - version: v1 - x-comment: >- - Generated by core-types-json-schema - (https://github.com/grantila/core-types-json-schema) on behalf of typeconv - (https://github.com/grantila/typeconv) -paths: {} -components: - schemas: - Point: - properties: - x: - title: The distance from the left in mm - type: number - 'y': - title: The distance from the top in mm - type: number - required: - - x - - 'y' - additionalProperties: false + title: Thing type: object " `; diff --git a/lib/tests/ts-to-openapi.test.ts b/lib/tests/ts-to-openapi.test.ts index 42f41be..c496b21 100644 --- a/lib/tests/ts-to-openapi.test.ts +++ b/lib/tests/ts-to-openapi.test.ts @@ -1,9 +1,9 @@ -import { makeConverter, getTypeScriptReader, getOpenApiWriter } from "../" +import { makeConverter, getTypeScriptReader, getOpenApiWriter } from '../' -describe( "ts-to-openapi", ( ) => +describe( 'ts-to-openapi', ( ) => { - it( "typescript to openapi", async ( ) => + it( 'typescript to openapi', async ( ) => { const input = ` type Thing = { @@ -34,7 +34,7 @@ describe( "ts-to-openapi", ( ) => expect( data ).toMatchSnapshot( ); } ); - it( "typescript to openapi", async ( ) => + it( 'ensure descriptions are forwarded', async ( ) => { const input = ` export type Point = { diff --git a/package.json b/package.json index d54a25c..0333222 100644 --- a/package.json +++ b/package.json @@ -53,11 +53,11 @@ "@babel/code-frame": "^7.15.8", "already": "^2.1.0", "chalk": "^4.1.2", - "core-types": "^1.9.1", - "core-types-graphql": "^1.3.1", - "core-types-json-schema": "^1.6.0", - "core-types-suretype": "^1.3.0", - "core-types-ts": "^1.4.1", + "core-types": "^1.10.0", + "core-types-graphql": "^1.4.0", + "core-types-json-schema": "^1.6.2", + "core-types-suretype": "^1.4.1", + "core-types-ts": "^1.5.0", "globby": "^11.0.3", "js-yaml": "^4.1.0", "oppa": "^0.4.0",