@aws/nx-plugin 0.14.1 → 0.14.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws/nx-plugin",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.2",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "https://github.com/awslabs/nx-plugin-for-aws.git",
|
|
7
|
+
"directory": "packages/nx-plugin"
|
|
8
|
+
},
|
|
4
9
|
"private": false,
|
|
5
10
|
"type": "commonjs",
|
|
6
11
|
"license": "Apache-2.0",
|
|
@@ -1509,6 +1509,279 @@ export class TestApi {
|
|
|
1509
1509
|
"
|
|
1510
1510
|
`;
|
|
1511
1511
|
|
|
1512
|
+
exports[`openApiTsClientGenerator > should generate valid typescript for openapi v3.1 specifications with null types 1`] = `
|
|
1513
|
+
"export type PostTest200Response = {};
|
|
1514
|
+
export type PostTestRequestContent = {
|
|
1515
|
+
requiredNull: null;
|
|
1516
|
+
optionalNull?: null;
|
|
1517
|
+
requiredCompositeNull: PostTestRequestContentRequiredCompositeNull;
|
|
1518
|
+
optionalCompositeNull?: PostTestRequestContentOptionalCompositeNull;
|
|
1519
|
+
};
|
|
1520
|
+
export type PostTestRequestContentOptionalCompositeNull = string | null;
|
|
1521
|
+
export type PostTestRequestContentRequiredCompositeNull = string | null;
|
|
1522
|
+
|
|
1523
|
+
export type PostTestRequest = PostTestRequestContent;
|
|
1524
|
+
export type PostTestError = never;
|
|
1525
|
+
"
|
|
1526
|
+
`;
|
|
1527
|
+
|
|
1528
|
+
exports[`openApiTsClientGenerator > should generate valid typescript for openapi v3.1 specifications with null types 2`] = `
|
|
1529
|
+
"import type {
|
|
1530
|
+
PostTest200Response,
|
|
1531
|
+
PostTestRequestContent,
|
|
1532
|
+
PostTestRequestContentOptionalCompositeNull,
|
|
1533
|
+
PostTestRequestContentRequiredCompositeNull,
|
|
1534
|
+
PostTestRequest,
|
|
1535
|
+
} from './types.gen.js';
|
|
1536
|
+
|
|
1537
|
+
/**
|
|
1538
|
+
* Utility for serialisation and deserialisation of API types.
|
|
1539
|
+
*/
|
|
1540
|
+
export class $IO {
|
|
1541
|
+
protected static $mapValues = (data: any, fn: (item: any) => any) =>
|
|
1542
|
+
Object.fromEntries(Object.entries(data).map(([k, v]) => [k, fn(v)]));
|
|
1543
|
+
|
|
1544
|
+
public static PostTest200Response = {
|
|
1545
|
+
toJson: (model: PostTest200Response): any => {
|
|
1546
|
+
if (model === undefined || model === null) {
|
|
1547
|
+
return model;
|
|
1548
|
+
}
|
|
1549
|
+
return {
|
|
1550
|
+
...model,
|
|
1551
|
+
};
|
|
1552
|
+
},
|
|
1553
|
+
fromJson: (json: any): PostTest200Response => {
|
|
1554
|
+
if (json === undefined || json === null) {
|
|
1555
|
+
return json;
|
|
1556
|
+
}
|
|
1557
|
+
return {
|
|
1558
|
+
...json,
|
|
1559
|
+
};
|
|
1560
|
+
},
|
|
1561
|
+
};
|
|
1562
|
+
|
|
1563
|
+
public static PostTestRequestContent = {
|
|
1564
|
+
toJson: (model: PostTestRequestContent): any => {
|
|
1565
|
+
if (model === undefined || model === null) {
|
|
1566
|
+
return model;
|
|
1567
|
+
}
|
|
1568
|
+
return {
|
|
1569
|
+
...(model.requiredNull === undefined
|
|
1570
|
+
? {}
|
|
1571
|
+
: {
|
|
1572
|
+
requiredNull: model.requiredNull,
|
|
1573
|
+
}),
|
|
1574
|
+
...(model.optionalNull === undefined
|
|
1575
|
+
? {}
|
|
1576
|
+
: {
|
|
1577
|
+
optionalNull: model.optionalNull,
|
|
1578
|
+
}),
|
|
1579
|
+
...(model.requiredCompositeNull === undefined
|
|
1580
|
+
? {}
|
|
1581
|
+
: {
|
|
1582
|
+
requiredCompositeNull:
|
|
1583
|
+
$IO.PostTestRequestContentRequiredCompositeNull.toJson(
|
|
1584
|
+
model.requiredCompositeNull,
|
|
1585
|
+
),
|
|
1586
|
+
}),
|
|
1587
|
+
...(model.optionalCompositeNull === undefined
|
|
1588
|
+
? {}
|
|
1589
|
+
: {
|
|
1590
|
+
optionalCompositeNull:
|
|
1591
|
+
$IO.PostTestRequestContentOptionalCompositeNull.toJson(
|
|
1592
|
+
model.optionalCompositeNull,
|
|
1593
|
+
),
|
|
1594
|
+
}),
|
|
1595
|
+
};
|
|
1596
|
+
},
|
|
1597
|
+
fromJson: (json: any): PostTestRequestContent => {
|
|
1598
|
+
if (json === undefined || json === null) {
|
|
1599
|
+
return json;
|
|
1600
|
+
}
|
|
1601
|
+
return {
|
|
1602
|
+
requiredNull:
|
|
1603
|
+
json['requiredNull'] === null ? null : json['requiredNull'],
|
|
1604
|
+
...(json['optionalNull'] === undefined
|
|
1605
|
+
? {}
|
|
1606
|
+
: {
|
|
1607
|
+
optionalNull:
|
|
1608
|
+
json['optionalNull'] === null ? null : json['optionalNull'],
|
|
1609
|
+
}),
|
|
1610
|
+
requiredCompositeNull:
|
|
1611
|
+
$IO.PostTestRequestContentRequiredCompositeNull.fromJson(
|
|
1612
|
+
json['requiredCompositeNull'],
|
|
1613
|
+
),
|
|
1614
|
+
...(json['optionalCompositeNull'] === undefined
|
|
1615
|
+
? {}
|
|
1616
|
+
: {
|
|
1617
|
+
optionalCompositeNull:
|
|
1618
|
+
$IO.PostTestRequestContentOptionalCompositeNull.fromJson(
|
|
1619
|
+
json['optionalCompositeNull'],
|
|
1620
|
+
),
|
|
1621
|
+
}),
|
|
1622
|
+
};
|
|
1623
|
+
},
|
|
1624
|
+
};
|
|
1625
|
+
|
|
1626
|
+
public static PostTestRequestContentOptionalCompositeNull = {
|
|
1627
|
+
toJson: (model: PostTestRequestContentOptionalCompositeNull): any => {
|
|
1628
|
+
if (model === undefined || model === null) {
|
|
1629
|
+
return model;
|
|
1630
|
+
}
|
|
1631
|
+
if (typeof model === 'string') {
|
|
1632
|
+
return model;
|
|
1633
|
+
}
|
|
1634
|
+
return model;
|
|
1635
|
+
},
|
|
1636
|
+
fromJson: (json: any): PostTestRequestContentOptionalCompositeNull => {
|
|
1637
|
+
if (json === undefined || json === null) {
|
|
1638
|
+
return json;
|
|
1639
|
+
}
|
|
1640
|
+
if (typeof json === 'string') {
|
|
1641
|
+
return json;
|
|
1642
|
+
}
|
|
1643
|
+
return json;
|
|
1644
|
+
},
|
|
1645
|
+
};
|
|
1646
|
+
|
|
1647
|
+
public static PostTestRequestContentRequiredCompositeNull = {
|
|
1648
|
+
toJson: (model: PostTestRequestContentRequiredCompositeNull): any => {
|
|
1649
|
+
if (model === undefined || model === null) {
|
|
1650
|
+
return model;
|
|
1651
|
+
}
|
|
1652
|
+
if (typeof model === 'string') {
|
|
1653
|
+
return model;
|
|
1654
|
+
}
|
|
1655
|
+
return model;
|
|
1656
|
+
},
|
|
1657
|
+
fromJson: (json: any): PostTestRequestContentRequiredCompositeNull => {
|
|
1658
|
+
if (json === undefined || json === null) {
|
|
1659
|
+
return json;
|
|
1660
|
+
}
|
|
1661
|
+
if (typeof json === 'string') {
|
|
1662
|
+
return json;
|
|
1663
|
+
}
|
|
1664
|
+
return json;
|
|
1665
|
+
},
|
|
1666
|
+
};
|
|
1667
|
+
}
|
|
1668
|
+
|
|
1669
|
+
/**
|
|
1670
|
+
* Client configuration for TestApi
|
|
1671
|
+
*/
|
|
1672
|
+
export interface TestApiConfig {
|
|
1673
|
+
/**
|
|
1674
|
+
* Base URL for the API
|
|
1675
|
+
*/
|
|
1676
|
+
url: string;
|
|
1677
|
+
/**
|
|
1678
|
+
* Custom instance of fetch. By default the global 'fetch' is used.
|
|
1679
|
+
* You can override this to add custom middleware for use cases such as adding authentication headers.
|
|
1680
|
+
*/
|
|
1681
|
+
fetch?: typeof fetch;
|
|
1682
|
+
/**
|
|
1683
|
+
* Additional configuration
|
|
1684
|
+
*/
|
|
1685
|
+
options?: {
|
|
1686
|
+
/**
|
|
1687
|
+
* By default, the client will add a Content-Type header, set to the media type defined for
|
|
1688
|
+
* the request in the OpenAPI specification.
|
|
1689
|
+
* Set this to false to omit this header.
|
|
1690
|
+
*/
|
|
1691
|
+
omitContentTypeHeader?: boolean;
|
|
1692
|
+
};
|
|
1693
|
+
}
|
|
1694
|
+
|
|
1695
|
+
/**
|
|
1696
|
+
* API Client for TestApi
|
|
1697
|
+
*/
|
|
1698
|
+
export class TestApi {
|
|
1699
|
+
private $config: TestApiConfig;
|
|
1700
|
+
|
|
1701
|
+
constructor(config: TestApiConfig) {
|
|
1702
|
+
this.$config = config;
|
|
1703
|
+
|
|
1704
|
+
this.postTest = this.postTest.bind(this);
|
|
1705
|
+
}
|
|
1706
|
+
|
|
1707
|
+
private $url = (
|
|
1708
|
+
path: string,
|
|
1709
|
+
pathParameters: { [key: string]: any },
|
|
1710
|
+
queryParameters: { [key: string]: any },
|
|
1711
|
+
collectionFormats?: { [key: string]: 'multi' | 'csv' },
|
|
1712
|
+
): string => {
|
|
1713
|
+
const baseUrl = this.$config.url.endsWith('/')
|
|
1714
|
+
? this.$config.url.slice(0, -1)
|
|
1715
|
+
: this.$config.url;
|
|
1716
|
+
const pathWithParameters = Object.entries(pathParameters).reduce(
|
|
1717
|
+
(withParams, [key, value]) =>
|
|
1718
|
+
withParams.replace(\`{\${key}}\`, encodeURIComponent(\`\${value}\`)),
|
|
1719
|
+
path,
|
|
1720
|
+
);
|
|
1721
|
+
const queryString = Object.entries(queryParameters)
|
|
1722
|
+
.map(([key, value]) => {
|
|
1723
|
+
if (Array.isArray(value) && collectionFormats?.[key] === 'multi') {
|
|
1724
|
+
return value
|
|
1725
|
+
.map(
|
|
1726
|
+
(v) => \`\${encodeURIComponent(key)}=\${encodeURIComponent(\`\${v}\`)}\`,
|
|
1727
|
+
)
|
|
1728
|
+
.join('&');
|
|
1729
|
+
}
|
|
1730
|
+
return \`\${encodeURIComponent(key)}=\${encodeURIComponent(Array.isArray(value) ? value.map(String).join(',') : String(value))}\`;
|
|
1731
|
+
})
|
|
1732
|
+
.join('&');
|
|
1733
|
+
return (
|
|
1734
|
+
baseUrl + pathWithParameters + (queryString ? \`?\${queryString}\` : '')
|
|
1735
|
+
);
|
|
1736
|
+
};
|
|
1737
|
+
|
|
1738
|
+
private $headers = (
|
|
1739
|
+
headerParameters: { [key: string]: any },
|
|
1740
|
+
collectionFormats?: { [key: string]: 'multi' | 'csv' },
|
|
1741
|
+
): [string, string][] => {
|
|
1742
|
+
return Object.entries(headerParameters).flatMap(([key, value]) => {
|
|
1743
|
+
if (Array.isArray(value) && collectionFormats?.[key] === 'multi') {
|
|
1744
|
+
return value.map((v) => [key, String(v)]) as [string, string][];
|
|
1745
|
+
}
|
|
1746
|
+
return [[key, String(value)]];
|
|
1747
|
+
});
|
|
1748
|
+
};
|
|
1749
|
+
|
|
1750
|
+
private $fetch: typeof fetch = (...args) =>
|
|
1751
|
+
(this.$config.fetch ?? fetch)(...args);
|
|
1752
|
+
|
|
1753
|
+
public async postTest(input: PostTestRequest): Promise<PostTest200Response> {
|
|
1754
|
+
const pathParameters: { [key: string]: any } = {};
|
|
1755
|
+
const queryParameters: { [key: string]: any } = {};
|
|
1756
|
+
const headerParameters: { [key: string]: any } = {};
|
|
1757
|
+
if (!this.$config.options?.omitContentTypeHeader) {
|
|
1758
|
+
headerParameters['Content-Type'] = 'application/json';
|
|
1759
|
+
}
|
|
1760
|
+
const body =
|
|
1761
|
+
typeof input === 'object'
|
|
1762
|
+
? JSON.stringify($IO.PostTestRequestContent.toJson(input))
|
|
1763
|
+
: String($IO.PostTestRequestContent.toJson(input));
|
|
1764
|
+
|
|
1765
|
+
const response = await this.$fetch(
|
|
1766
|
+
this.$url('/test', pathParameters, queryParameters),
|
|
1767
|
+
{
|
|
1768
|
+
headers: this.$headers(headerParameters),
|
|
1769
|
+
method: 'POST',
|
|
1770
|
+
body,
|
|
1771
|
+
},
|
|
1772
|
+
);
|
|
1773
|
+
|
|
1774
|
+
if (response.status === 200) {
|
|
1775
|
+
return $IO.PostTest200Response.fromJson(await response.json());
|
|
1776
|
+
}
|
|
1777
|
+
throw new Error(
|
|
1778
|
+
\`Unknown response status \${response.status} returned by API\`,
|
|
1779
|
+
);
|
|
1780
|
+
}
|
|
1781
|
+
}
|
|
1782
|
+
"
|
|
1783
|
+
`;
|
|
1784
|
+
|
|
1512
1785
|
exports[`openApiTsClientGenerator > should handle composite primitive and array request bodies 1`] = `
|
|
1513
1786
|
"export type CompositeRequestContent =
|
|
1514
1787
|
| string
|
|
@@ -32,7 +32,7 @@ import type {
|
|
|
32
32
|
// eg. an array of arrays of strings doesn't need to be rendered as `value.map(item0 => item0.map(item1 => item1))`
|
|
33
33
|
const canShortCircuitConversion = (property) => {
|
|
34
34
|
if (["array", "dictionary"].includes(property.export)) {
|
|
35
|
-
return canShortCircuitConversion(property.link);
|
|
35
|
+
return !property.link || canShortCircuitConversion(property.link);
|
|
36
36
|
}
|
|
37
37
|
return property.isPrimitive && !["date", "date-time"].includes(property.format);
|
|
38
38
|
};
|
|
@@ -164,7 +164,7 @@ export class $IO {
|
|
|
164
164
|
return model;
|
|
165
165
|
}
|
|
166
166
|
<%_ if (isComposite) { _%>
|
|
167
|
-
<%_ model.composedPrimitives.filter(p => !['array', 'dictionary'].includes(p.export)).forEach((primitive) => { _%>
|
|
167
|
+
<%_ model.composedPrimitives.filter(p => !['array', 'dictionary'].includes(p.export) && p.type !== 'null').forEach((primitive) => { _%>
|
|
168
168
|
if (typeof model === "<%- primitive.typescriptType %>") {
|
|
169
169
|
return model;
|
|
170
170
|
}
|
|
@@ -209,7 +209,7 @@ export class $IO {
|
|
|
209
209
|
return json;
|
|
210
210
|
}
|
|
211
211
|
<%_ if (isComposite) { _%>
|
|
212
|
-
<%_ model.composedPrimitives.filter(p => !['array', 'dictionary'].includes(p.export)).forEach((primitive) => { _%>
|
|
212
|
+
<%_ model.composedPrimitives.filter(p => !['array', 'dictionary'].includes(p.export) && p.type !== 'null').forEach((primitive) => { _%>
|
|
213
213
|
if (typeof json === "<%- primitive.typescriptType %>") {
|
|
214
214
|
return json;
|
|
215
215
|
}
|
|
@@ -27,12 +27,12 @@ _%>
|
|
|
27
27
|
<%_ } else if (isComposite) { _%>
|
|
28
28
|
<%- docString(model, '') %>export type <%- model.name %> =<% model.properties.forEach((composedType, i) => { %><% if (i > 0) { %><% if (model.export === "all-of") { %> &<% } else { %> |<% } %><% } %> <%- composedType.typescriptType %><% }); %>;
|
|
29
29
|
<%_ } else { _%>
|
|
30
|
-
<%- docString(model, '') %>export type <%= model.name %> = <% if (model.isNullable) { %>null | <% } %>{
|
|
30
|
+
<%- docString(model, '') %>export type <%= model.name %> = <% if (model.isNullable && model.type !== 'null') { %>null | <% } %>{
|
|
31
31
|
<%_ if (model.export === "dictionary" && model.link) { _%>
|
|
32
32
|
<%- docString(model.link, ' ') %> [key: string]: <%- model.link.typescriptType %>;
|
|
33
33
|
<%_ } _%>
|
|
34
34
|
<%_ model.properties.forEach((property) => { _%>
|
|
35
|
-
<%- docString(property, ' ') %> <%= property.isReadOnly ? 'readonly ' : '' %><%= property.typescriptName %><%= property.isRequired ? '' : '?' %>: <%- property.typescriptType %><%= property.isNullable ? ' | null' : '' %>;
|
|
35
|
+
<%- docString(property, ' ') %> <%= property.isReadOnly ? 'readonly ' : '' %><%= property.typescriptName %><%= property.isRequired ? '' : '?' %>: <%- property.typescriptType %><%= (property.isNullable && property.type !== 'null') ? ' | null' : '' %>;
|
|
36
36
|
<%_ }); _%>
|
|
37
37
|
};
|
|
38
38
|
<%_ } _%>
|