Skip to content

Commit

Permalink
feat(core): generate typescript models from swagger/openapi project (#…
Browse files Browse the repository at this point in the history
…447)

This is experimental, and currently disabled by default.
  • Loading branch information
AgentEnder authored Jul 1, 2022
1 parent e4365a9 commit cd56d1c
Show file tree
Hide file tree
Showing 96 changed files with 3,905 additions and 235 deletions.
10 changes: 10 additions & 0 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"version": 1,
"isRoot": true,
"tools": {
"swashbuckle.aspnetcore.cli": {
"version": "6.2.3",
"commands": ["swagger"]
}
}
}
5 changes: 5 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@
"files": ["*.js", "*.jsx"],
"extends": ["plugin:@nrwl/nx/javascript"],
"rules": {}
},
{
"files": "*.json",
"parser": "jsonc-eslint-parser",
"rules": {}
}
]
}
3 changes: 3 additions & 0 deletions .nx-dotnet.rc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"nugetPackages": {}
}
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,6 @@
"orderLevel": 40
}
],
"liveServer.settings.port": 5501
"liveServer.settings.port": 5501,
"eslint.validate": ["json"]
}
11 changes: 11 additions & 0 deletions demo/apps/web-frontend/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"presets": [
[
"@nrwl/react/babel",
{
"runtime": "automatic"
}
]
],
"plugins": []
}
16 changes: 16 additions & 0 deletions demo/apps/web-frontend/.browserslistrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# This file is used by:
# 1. autoprefixer to adjust CSS to support the below specified browsers
# 2. babel preset-env to adjust included polyfills
#
# For additional information regarding the format and rule options, please see:
# https://github.com/browserslist/browserslist#queries
#
# If you need to support different browsers in production, you may tweak the list below.

last 1 Chrome version
last 1 Firefox version
last 2 Edge major versions
last 2 Safari major version
last 2 iOS major versions
Firefox ESR
not IE 9-11 # For IE 9-11 support, remove 'not'.
18 changes: 18 additions & 0 deletions demo/apps/web-frontend/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["plugin:@nrwl/nx/react", "../../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
11 changes: 11 additions & 0 deletions demo/apps/web-frontend/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* eslint-disable */
export default {
displayName: 'demo-web-frontend',
preset: '../../../jest.preset.js',
transform: {
'^(?!.*\\.(js|jsx|ts|tsx|css|json)$)': '@nrwl/react/plugins/jest',
'^.+\\.[tj]sx?$': 'babel-jest',
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
coverageDirectory: '../../coverage//demo/apps/web-frontend',
};
83 changes: 83 additions & 0 deletions demo/apps/web-frontend/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
{
"$schema": "../../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "demo/apps/web-frontend/src",
"projectType": "application",
"targets": {
"build": {
"executor": "@nrwl/web:webpack",
"outputs": ["{options.outputPath}"],
"defaultConfiguration": "production",
"options": {
"compiler": "babel",
"outputPath": "dist/demo/apps/web-frontend",
"index": "demo/apps/web-frontend/src/index.html",
"baseHref": "/",
"main": "demo/apps/web-frontend/src/main.tsx",
"polyfills": "demo/apps/web-frontend/src/polyfills.ts",
"tsConfig": "demo/apps/web-frontend/tsconfig.app.json",
"assets": [
"demo/apps/web-frontend/src/favicon.ico",
"demo/apps/web-frontend/src/assets"
],
"styles": ["demo/apps/web-frontend/src/styles.scss"],
"scripts": [],
"webpackConfig": "@nrwl/react/plugins/webpack"
},
"configurations": {
"production": {
"fileReplacements": [
{
"replace": "demo/apps/web-frontend/src/environments/environment.ts",
"with": "demo/apps/web-frontend/src/environments/environment.prod.ts"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"namedChunks": false,
"extractLicenses": true,
"vendorChunk": false
},
"development": {
"extractLicenses": false,
"optimization": false,
"sourceMap": true,
"vendorChunk": true
}
}
},
"serve": {
"executor": "@nrwl/web:dev-server",
"options": {
"buildTarget": "demo-web-frontend:build",
"hmr": true
},
"configurations": {
"production": {
"buildTarget": "demo-web-frontend:build:production",
"hmr": false
},
"development": {
"buildTarget": "demo-web-frontend:build:development"
}
},
"defaultConfiguration": "development"
},
"lint": {
"executor": "@nrwl/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["demo/apps/web-frontend/**/*.{ts,tsx,js,jsx}"]
}
},
"test": {
"executor": "@nrwl/jest:jest",
"outputs": ["coveragedemo/apps/web-frontend"],
"options": {
"jestConfig": "demo/apps/web-frontend/jest.config.ts",
"passWithNoTests": true
}
}
},
"tags": []
}
1 change: 1 addition & 0 deletions demo/apps/web-frontend/src/app/app.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* Your styles goes here. */
11 changes: 11 additions & 0 deletions demo/apps/web-frontend/src/app/app.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { render } from '@testing-library/react';

import App from './app';

describe('App', () => {
it('should render successfully', () => {
const { baseElement } = render(<App />);

expect(baseElement).toBeTruthy();
});
});
20 changes: 20 additions & 0 deletions demo/apps/web-frontend/src/app/app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* eslint-disable @typescript-eslint/no-unused-vars */

import styles from './app.module.scss';

import { WeatherForecast } from '@nx-dotnet/demo-libs-generated-webapi-types';

const x: WeatherForecast = {
date: 'TAOSNAPS',
summary: 'My weather forecast',
temperature: {
temperatureC: 12,
temperatureF: 53,
},
};

export function App() {
return <div />;
}

export default App;
Empty file.
3 changes: 3 additions & 0 deletions demo/apps/web-frontend/src/environments/environment.prod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const environment = {
production: true,
};
6 changes: 6 additions & 0 deletions demo/apps/web-frontend/src/environments/environment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// This file can be replaced during build by using the `fileReplacements` array.
// When building for production, this file is replaced with `environment.prod.ts`.

export const environment = {
production: false,
};
Binary file added demo/apps/web-frontend/src/favicon.ico
Binary file not shown.
14 changes: 14 additions & 0 deletions demo/apps/web-frontend/src/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>DemoWebFrontend</title>
<base href="/" />

<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" type="image/x-icon" href="favicon.ico" />
</head>
<body>
<div id="root"></div>
</body>
</html>
14 changes: 14 additions & 0 deletions demo/apps/web-frontend/src/main.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { StrictMode } from 'react';
import * as ReactDOMClient from 'react-dom/client';

import App from './app/app';

const root = ReactDOMClient.createRoot(
document.getElementById('root') as HTMLElement,
);

root.render(
<StrictMode>
<App />
</StrictMode>,
);
7 changes: 7 additions & 0 deletions demo/apps/web-frontend/src/polyfills.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* Polyfill stable language features. These imports will be optimized by `@babel/preset-env`.
*
* See: https://github.com/zloirock/core-js#babel
*/
import 'core-js/stable';
import 'regenerator-runtime/runtime';
1 change: 1 addition & 0 deletions demo/apps/web-frontend/src/styles.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* You can add global styles to this file, and also import other style files */
23 changes: 23 additions & 0 deletions demo/apps/web-frontend/tsconfig.app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"types": ["node"]
},
"files": [
"../../../node_modules/@nrwl/react/typings/cssmodule.d.ts",
"../../../node_modules/@nrwl/react/typings/image.d.ts"
],
"exclude": [
"**/*.spec.ts",
"**/*.test.ts",
"**/*.spec.tsx",
"**/*.test.tsx",
"**/*.spec.js",
"**/*.test.js",
"**/*.spec.jsx",
"**/*.test.jsx",
"jest.config.ts"
],
"include": ["**/*.js", "**/*.jsx", "**/*.ts", "**/*.tsx"]
}
25 changes: 25 additions & 0 deletions demo/apps/web-frontend/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"extends": "../../../tsconfig.base.json",
"compilerOptions": {
"jsx": "react-jsx",
"allowJs": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true
},
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.app.json"
},
{
"path": "./tsconfig.spec.json"
}
]
}
24 changes: 24 additions & 0 deletions demo/apps/web-frontend/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
},
"include": [
"**/*.test.ts",
"**/*.spec.ts",
"**/*.test.tsx",
"**/*.spec.tsx",
"**/*.test.js",
"**/*.spec.js",
"**/*.test.jsx",
"**/*.spec.jsx",
"**/*.d.ts",
"jest.config.ts"
],
"files": [
"../../../node_modules/@nrwl/react/typings/cssmodule.d.ts",
"../../../node_modules/@nrwl/react/typings/image.d.ts"
]
}
35 changes: 35 additions & 0 deletions demo/apps/webapi/Controllers/WeatherForecastController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Microsoft.AspNetCore.Mvc;

namespace NxDotnet.Test.Webapi.Controllers;

[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
private static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};

private readonly ILogger<WeatherForecastController> _logger;

public WeatherForecastController(ILogger<WeatherForecastController> logger)
{
_logger = logger;
}

[HttpGet(Name = "GetWeatherForecast")]
public IEnumerable<WeatherForecast> Get()
{
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = DateTime.Now.AddDays(index),
Temperature = new Temperature
{
TemperatureC = Random.Shared.Next(-20, 55),
},
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
})
.ToArray();
}
}
20 changes: 20 additions & 0 deletions demo/apps/webapi/NxDotnet.Test.Webapi.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>

<TargetFramework>net6.0</TargetFramework>

<Nullable>enable</Nullable>

<ImplicitUsings>enable</ImplicitUsings>

<OutputPath>../../../dist/demo/apps/webapi</OutputPath>
</PropertyGroup>

<ItemGroup>

<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3"/>

</ItemGroup>

</Project>
Loading

0 comments on commit cd56d1c

Please sign in to comment.