Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ Digital Citizenship initiative.
To add the tools to a project:

```
$ yarn add -D italia-utils
$ yarn add -D io-utils
```

## gen-api-models

This tool generates TypeScript definitions of OpenAPI specs.

In simple terms it converts an OpenAPI spec like [this one](https://github.com/teamdigitale/digital-citizenship-functions/blob/f04666c8b7f2d4bebde19676b49b19119b03ef17/api/public_api_v1.yaml) into:
In simple terms it converts an OpenAPI spec like [this one](https://github.com/teamdigitale/io-functions/blob/f04666c8b7f2d4bebde19676b49b19119b03ef17/api/public_api_v1.yaml) into:

* A TypeScript [representation of the specs](https://github.com/teamdigitale/digital-citizenship-functions/blob/6798225bd725a42753b16375ce18a954a268f9b6/lib/api/public_api_v1.ts).
* An [io-ts](https://github.com/gcanti/io-ts) type definitions for [each API definition](https://github.com/teamdigitale/digital-citizenship-functions/tree/6798225bd725a42753b16375ce18a954a268f9b6/lib/api/definitions) that provides compile time types and runtime validation.
* A TypeScript [representation of the specs](https://github.com/teamdigitale/io-functions/blob/6798225bd725a42753b16375ce18a954a268f9b6/lib/api/public_api_v1.ts).
* An [io-ts](https://github.com/gcanti/io-ts) type definitions for [each API definition](https://github.com/teamdigitale/io-functions/tree/6798225bd725a42753b16375ce18a954a268f9b6/lib/api/definitions) that provides compile time types and runtime validation.

Note: the generated models requires the runtime dependency `italia-ts-commons`.
Note: the generated models requires the runtime dependency `io-ts-commons`.

### Usage

Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "italia-utils",
"name": "io-utils",
"version": "3.15.2",
"description": "Tools and utilities for the Digital Citizenship project",
"repository": "https://github.com/teamdigitale/italia-utils",
"repository": "https://github.com/teamdigitale/io-utils",
"author": "https://teamdigitale.governo.it",
"license": "MIT",
"bin": {
Expand All @@ -22,7 +22,7 @@
},
"dependencies": {
"fs-extra": "^6.0.0",
"italia-ts-commons": "^2.14.0",
"io-ts-commons": "^2.14.0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note that the name of packages in npm is still italia-utils and italia-ts-commons so this cannot work

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gunzip I think we can close di PR (was create on feb 2019)

"nunjucks": "^3.1.2",
"prettier": "^1.12.1",
"swagger-parser": "^4.1.0",
Expand Down Expand Up @@ -65,4 +65,4 @@
"**/__tests__/*.ts"
]
}
}
}
90 changes: 45 additions & 45 deletions src/__tests__/__snapshots__/gen-api-models.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

exports[`gen-api-models should generate a dictionary from additionalProperties: additional-properties 1`] = `
"/**
* Do not edit this file it is auto-generated by italia-utils / gen-api-models.
* See https://github.com/teamdigitale/italia-utils
* Do not edit this file it is auto-generated by io-utils / gen-api-models.
* See https://github.com/teamdigitale/io-utils
*/
/* tslint:disable */

Expand All @@ -25,8 +25,8 @@ export type AdditionalPropsTest = t.TypeOf<typeof AdditionalPropsTest>;

exports[`gen-api-models should generate a dictionary from additionalProperties: true: additional-properties-true 1`] = `
"/**
* Do not edit this file it is auto-generated by italia-utils / gen-api-models.
* See https://github.com/teamdigitale/italia-utils
* Do not edit this file it is auto-generated by io-utils / gen-api-models.
* See https://github.com/teamdigitale/io-utils
*/
/* tslint:disable */

Expand All @@ -46,8 +46,8 @@ export type AdditionalPropsTrueTest = t.TypeOf<typeof AdditionalPropsTrueTest>;

exports[`gen-api-models should generate a type intersection from allOf: all-of-test 1`] = `
"/**
* Do not edit this file it is auto-generated by italia-utils / gen-api-models.
* See https://github.com/teamdigitale/italia-utils
* Do not edit this file it is auto-generated by io-utils / gen-api-models.
* See https://github.com/teamdigitale/io-utils
*/
/* tslint:disable */

Expand Down Expand Up @@ -81,8 +81,8 @@ export type AllOfTest = t.TypeOf<typeof AllOfTest>;

exports[`gen-api-models should generate a type union from allOf when x-one-of is used: allofoneof-test 1`] = `
"/**
* Do not edit this file it is auto-generated by italia-utils / gen-api-models.
* See https://github.com/teamdigitale/italia-utils
* Do not edit this file it is auto-generated by io-utils / gen-api-models.
* See https://github.com/teamdigitale/io-utils
*/
/* tslint:disable */

Expand Down Expand Up @@ -116,8 +116,8 @@ export type AllOfOneOfTest = t.TypeOf<typeof AllOfOneOfTest>;

exports[`gen-api-models should generate a type union from oneOf: oneof-test 1`] = `
"/**
* Do not edit this file it is auto-generated by italia-utils / gen-api-models.
* See https://github.com/teamdigitale/italia-utils
* Do not edit this file it is auto-generated by io-utils / gen-api-models.
* See https://github.com/teamdigitale/io-utils
*/
/* tslint:disable */

Expand Down Expand Up @@ -177,12 +177,12 @@ exports[`gen-api-models should generate the operator definition 1`] = `

exports[`gen-api-models should handle CustomStringFormats: custom-string-format 1`] = `
"/**
* Do not edit this file it is auto-generated by italia-utils / gen-api-models.
* See https://github.com/teamdigitale/italia-utils
* Do not edit this file it is auto-generated by io-utils / gen-api-models.
* See https://github.com/teamdigitale/io-utils
*/
/* tslint:disable */

import { SomeCustomStringType as SomeCustomStringTypeT } from \\"italia-ts-commons/lib/string\\";
import { SomeCustomStringType as SomeCustomStringTypeT } from \\"io-ts-commons/lib/string\\";
import * as t from \\"io-ts\\";

export type CustomStringFormatTest = t.TypeOf<typeof CustomStringFormatTest>;
Expand All @@ -192,12 +192,12 @@ export const CustomStringFormatTest = SomeCustomStringTypeT;

exports[`gen-api-models should handle NonNegativeIntegers: non-negative-integer 1`] = `
"/**
* Do not edit this file it is auto-generated by italia-utils / gen-api-models.
* See https://github.com/teamdigitale/italia-utils
* Do not edit this file it is auto-generated by io-utils / gen-api-models.
* See https://github.com/teamdigitale/io-utils
*/
/* tslint:disable */

import { NonNegativeInteger } from \\"italia-ts-commons/lib/numbers\\";
import { NonNegativeInteger } from \\"io-ts-commons/lib/numbers\\";
import * as t from \\"io-ts\\";

export type NonNegativeIntegerTest = t.TypeOf<typeof NonNegativeIntegerTest>;
Expand All @@ -207,12 +207,12 @@ export const NonNegativeIntegerTest = NonNegativeInteger;

exports[`gen-api-models should handle NonNegativeNumbers: non-negative-numbers 1`] = `
"/**
* Do not edit this file it is auto-generated by italia-utils / gen-api-models.
* See https://github.com/teamdigitale/italia-utils
* Do not edit this file it is auto-generated by io-utils / gen-api-models.
* See https://github.com/teamdigitale/io-utils
*/
/* tslint:disable */

import { NonNegativeNumber } from \\"italia-ts-commons/lib/numbers\\";
import { NonNegativeNumber } from \\"io-ts-commons/lib/numbers\\";
import * as t from \\"io-ts\\";

export type NonNegativeNumberTest = t.TypeOf<typeof NonNegativeNumberTest>;
Expand All @@ -222,12 +222,12 @@ export const NonNegativeNumberTest = NonNegativeNumber;

exports[`gen-api-models should handle WithinRangeIntegers: within-range-integer 1`] = `
"/**
* Do not edit this file it is auto-generated by italia-utils / gen-api-models.
* See https://github.com/teamdigitale/italia-utils
* Do not edit this file it is auto-generated by io-utils / gen-api-models.
* See https://github.com/teamdigitale/io-utils
*/
/* tslint:disable */

import { WithinRangeInteger } from \\"italia-ts-commons/lib/numbers\\";
import { WithinRangeInteger } from \\"io-ts-commons/lib/numbers\\";
import * as t from \\"io-ts\\";

export type WithinRangeIntegerTest = t.TypeOf<typeof WithinRangeIntegerTest>;
Expand All @@ -237,12 +237,12 @@ export const WithinRangeIntegerTest = WithinRangeInteger(0, 10);

exports[`gen-api-models should handle WithinRangeNumbers: within-range-numbers 1`] = `
"/**
* Do not edit this file it is auto-generated by italia-utils / gen-api-models.
* See https://github.com/teamdigitale/italia-utils
* Do not edit this file it is auto-generated by io-utils / gen-api-models.
* See https://github.com/teamdigitale/io-utils
*/
/* tslint:disable */

import { WithinRangeNumber } from \\"italia-ts-commons/lib/numbers\\";
import { WithinRangeNumber } from \\"io-ts-commons/lib/numbers\\";
import * as t from \\"io-ts\\";

export type WithinRangeNumberTest = t.TypeOf<typeof WithinRangeNumberTest>;
Expand All @@ -252,12 +252,12 @@ export const WithinRangeNumberTest = WithinRangeNumber(0, 10);

exports[`gen-api-models should handle WithinRangeStrings: within-range-strings 1`] = `
"/**
* Do not edit this file it is auto-generated by italia-utils / gen-api-models.
* See https://github.com/teamdigitale/italia-utils
* Do not edit this file it is auto-generated by io-utils / gen-api-models.
* See https://github.com/teamdigitale/io-utils
*/
/* tslint:disable */

import { WithinRangeString } from \\"italia-ts-commons/lib/strings\\";
import { WithinRangeString } from \\"io-ts-commons/lib/strings\\";
import * as t from \\"io-ts\\";

export type WithinRangeStringTest = t.TypeOf<typeof WithinRangeStringTest>;
Expand All @@ -267,13 +267,13 @@ export const WithinRangeStringTest = WithinRangeString(10, 11);

exports[`gen-api-models should handle enums: enum-simple 1`] = `
"/**
* Do not edit this file it is auto-generated by italia-utils / gen-api-models.
* See https://github.com/teamdigitale/italia-utils
* Do not edit this file it is auto-generated by io-utils / gen-api-models.
* See https://github.com/teamdigitale/io-utils
*/
/* tslint:disable */

import * as t from \\"io-ts\\";
import { enumType } from \\"italia-ts-commons/lib/types\\";
import { enumType } from \\"io-ts-commons/lib/types\\";

export enum StatusEnum {
\\"value1\\" = \\"value1\\",
Expand All @@ -299,12 +299,12 @@ export type EnumTest = t.TypeOf<typeof EnumTest>;

exports[`gen-api-models should include aliases for types already defined elsewhere if they have a different name: defined-type 1`] = `
"/**
* Do not edit this file it is auto-generated by italia-utils / gen-api-models.
* See https://github.com/teamdigitale/italia-utils
* Do not edit this file it is auto-generated by io-utils / gen-api-models.
* See https://github.com/teamdigitale/io-utils
*/
/* tslint:disable */

import { OrganizationFiscalCode as OrganizationFiscalCodeT } from \\"italia-ts-commons/lib/string\\";
import { OrganizationFiscalCode as OrganizationFiscalCodeT } from \\"io-ts-commons/lib/string\\";
import * as t from \\"io-ts\\";

export type OrganizationFiscalCodeTest = t.TypeOf<
Expand All @@ -316,8 +316,8 @@ export const OrganizationFiscalCodeTest = OrganizationFiscalCodeT;

exports[`gen-api-models should not generate duplicate imports: dup-imports 1`] = `
"/**
* Do not edit this file it is auto-generated by italia-utils / gen-api-models.
* See https://github.com/teamdigitale/italia-utils
* Do not edit this file it is auto-generated by io-utils / gen-api-models.
* See https://github.com/teamdigitale/io-utils
*/
/* tslint:disable */

Expand Down Expand Up @@ -383,13 +383,13 @@ export type Profile = t.TypeOf<typeof Profile>;

exports[`gen-api-models should parse custom inline properties: inline-property 1`] = `
"/**
* Do not edit this file it is auto-generated by italia-utils / gen-api-models.
* See https://github.com/teamdigitale/italia-utils
* Do not edit this file it is auto-generated by io-utils / gen-api-models.
* See https://github.com/teamdigitale/io-utils
*/
/* tslint:disable */

import * as t from \\"io-ts\\";
import { PatternString } from \\"italia-ts-commons/lib/strings\\";
import { PatternString } from \\"io-ts-commons/lib/strings\\";

// required attributes
const InlinePropertyTestR = t.interface({});
Expand All @@ -412,13 +412,13 @@ export type InlinePropertyTest = t.TypeOf<typeof InlinePropertyTest>;

exports[`gen-api-models should parse nested objects: nested-object 1`] = `
"/**
* Do not edit this file it is auto-generated by italia-utils / gen-api-models.
* See https://github.com/teamdigitale/italia-utils
* Do not edit this file it is auto-generated by io-utils / gen-api-models.
* See https://github.com/teamdigitale/io-utils
*/
/* tslint:disable */

import * as t from \\"io-ts\\";
import { PatternString } from \\"italia-ts-commons/lib/strings\\";
import { PatternString } from \\"io-ts-commons/lib/strings\\";

// required attributes
const NestedObjectTestNestedObjectR = t.interface({});
Expand Down Expand Up @@ -462,13 +462,13 @@ export type NestedObjectTest = t.TypeOf<typeof NestedObjectTest>;

exports[`gen-api-models should support additionalProperties default value: additional-properties-default 1`] = `
"/**
* Do not edit this file it is auto-generated by italia-utils / gen-api-models.
* See https://github.com/teamdigitale/italia-utils
* Do not edit this file it is auto-generated by io-utils / gen-api-models.
* See https://github.com/teamdigitale/io-utils
*/
/* tslint:disable */

import * as t from \\"io-ts\\";
import { withDefault } from \\"italia-ts-commons/lib/types\\";
import { withDefault } from \\"io-ts-commons/lib/types\\";

type AdditionalpropsDefaultBase = t.TypeOf<typeof AdditionalpropsDefaultBase>;
const AdditionalpropsDefaultBase = t.dictionary(
Expand Down
28 changes: 14 additions & 14 deletions src/__tests__/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,15 @@ definitions:
pattern: "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$"
CustomStringFormatTest:
type: string
x-import: italia-ts-commons/lib/string
x-import: io-ts-commons/lib/string
format: SomeCustomStringType
OrganizationFiscalCode:
type: string
x-import: italia-ts-commons/lib/string
x-import: io-ts-commons/lib/string
format: OrganizationFiscalCode
OrganizationFiscalCodeTest:
type: string
x-import: italia-ts-commons/lib/string
x-import: io-ts-commons/lib/string
format: OrganizationFiscalCode
NonNegativeIntegerTest:
title: NonNegativeIntegerTest
Expand Down Expand Up @@ -156,27 +156,27 @@ definitions:
- value2
- value3
MessageContent:
$ref: "https://raw.githubusercontent.com/teamdigitale/digital-citizenship-functions/v0.38.0/api/definitions.yaml#/MessageContent"
$ref: "https://raw.githubusercontent.com/teamdigitale/io-functions/v0.38.0/api/definitions.yaml#/MessageContent"
FiscalCode:
$ref: "https://raw.githubusercontent.com/teamdigitale/digital-citizenship-functions/v0.38.0/api/definitions.yaml#/FiscalCode"
$ref: "https://raw.githubusercontent.com/teamdigitale/io-functions/v0.38.0/api/definitions.yaml#/FiscalCode"
EmailAddress:
$ref: "https://raw.githubusercontent.com/teamdigitale/digital-citizenship-functions/v0.38.0/api/definitions.yaml#/EmailAddress"
$ref: "https://raw.githubusercontent.com/teamdigitale/io-functions/v0.38.0/api/definitions.yaml#/EmailAddress"
ExtendedProfile:
$ref: "https://raw.githubusercontent.com/teamdigitale/digital-citizenship-functions/v0.38.0/api/definitions.yaml#/ExtendedProfile"
$ref: "https://raw.githubusercontent.com/teamdigitale/io-functions/v0.38.0/api/definitions.yaml#/ExtendedProfile"
LimitedProfile:
$ref: "https://raw.githubusercontent.com/teamdigitale/digital-citizenship-functions/v0.38.0/api/definitions.yaml#/LimitedProfile"
$ref: "https://raw.githubusercontent.com/teamdigitale/io-functions/v0.38.0/api/definitions.yaml#/LimitedProfile"
PreferredLanguages:
$ref: "https://raw.githubusercontent.com/teamdigitale/digital-citizenship-functions/v0.38.0/api/definitions.yaml#/PreferredLanguages"
$ref: "https://raw.githubusercontent.com/teamdigitale/io-functions/v0.38.0/api/definitions.yaml#/PreferredLanguages"
IsInboxEnabled:
$ref: "https://raw.githubusercontent.com/teamdigitale/digital-citizenship-functions/v0.38.0/api/definitions.yaml#/IsInboxEnabled"
$ref: "https://raw.githubusercontent.com/teamdigitale/io-functions/v0.38.0/api/definitions.yaml#/IsInboxEnabled"
IsWebhookEnabled:
$ref: "https://raw.githubusercontent.com/teamdigitale/digital-citizenship-functions/v0.38.0/api/definitions.yaml#/IsWebhookEnabled"
$ref: "https://raw.githubusercontent.com/teamdigitale/io-functions/v0.38.0/api/definitions.yaml#/IsWebhookEnabled"
PaginationResponse:
$ref: "https://raw.githubusercontent.com/teamdigitale/digital-citizenship-functions/v0.38.0/api/definitions.yaml#/PaginationResponse"
$ref: "https://raw.githubusercontent.com/teamdigitale/io-functions/v0.38.0/api/definitions.yaml#/PaginationResponse"
CreatedMessageWithContent:
$ref: "https://raw.githubusercontent.com/teamdigitale/digital-citizenship-functions/v0.38.0/api/definitions.yaml#/CreatedMessageWithContent"
$ref: "https://raw.githubusercontent.com/teamdigitale/io-functions/v0.38.0/api/definitions.yaml#/CreatedMessageWithContent"
ServicePublic:
$ref: "https://raw.githubusercontent.com/teamdigitale/digital-citizenship-functions/v0.38.0/api/definitions.yaml#/ServicePublic"
$ref: "https://raw.githubusercontent.com/teamdigitale/io-functions/v0.38.0/api/definitions.yaml#/ServicePublic"
Message:
title: Message
type: object
Expand Down
4 changes: 2 additions & 2 deletions src/gen-api-models.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// tslint:disable:no-console

import * as fs from "fs-extra";
import { ITuple2, Tuple2 } from "italia-ts-commons/lib/tuples";
import { ITuple2, Tuple2 } from "io-ts-commons/lib/tuples";
import * as nunjucks from "nunjucks";
import * as prettier from "prettier";
import * as SwaggerParser from "swagger-parser";
Expand Down Expand Up @@ -434,7 +434,7 @@ export async function generateApi(

import * as t from "io-ts";

import * as r from "italia-ts-commons/lib/requests";
import * as r from "io-ts-commons/lib/requests";

${Array.from(operationsImports.values())
.map(i => `import { ${i} } from "./${i}";`)
Expand Down
Loading