Skip to content

Commit

Permalink
Use openapi generator (#1)
Browse files Browse the repository at this point in the history
* Add Echo.OpenAPI
  • Loading branch information
atrakic authored Jun 8, 2024
1 parent 0d5d442 commit ec1364e
Show file tree
Hide file tree
Showing 40 changed files with 1,624 additions and 206 deletions.
1 change: 0 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,3 @@ jobs:

- name: Test
run: dotnet test --no-restore --verbosity normal

23 changes: 23 additions & 0 deletions .openapi-generator-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# OpenAPI Generator Ignore
# Generated by openapi-generator https://github.com/openapitools/openapi-generator

# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.

# As an example, the C# client generator defines ApiClient.cs.
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
#ApiClient.cs

# You can match any string of characters against a directory, file or extension with a single asterisk (*):
#foo/*/qux
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux

# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
#foo/**/qux
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux

# You can also negate patterns with an exclamation (!).
# For example, you can ignore all files in a docs folder with the file extension .md:
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md
33 changes: 0 additions & 33 deletions Dotnet.Openapi.sln

This file was deleted.

22 changes: 22 additions & 0 deletions Echo.OpenAPI.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27428.2043
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Echo.OpenAPI", "src\Echo.OpenAPI\Echo.OpenAPI.csproj", "{28CA127C-200D-4F9B-8AF4-2B1D44D71727}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{28CA127C-200D-4F9B-8AF4-2B1D44D71727}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{28CA127C-200D-4F9B-8AF4-2B1D44D71727}.Debug|Any CPU.Build.0 = Debug|Any CPU
{28CA127C-200D-4F9B-8AF4-2B1D44D71727}.Release|Any CPU.ActiveCfg = Release|Any CPU
{28CA127C-200D-4F9B-8AF4-2B1D44D71727}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
13 changes: 5 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@ all:
dotnet build --configuration Release --no-restore
dotnet test --no-restore --verbosity normal

HELP_ARGS ?= config-help -g aspnetcore

help: ### make help HELP_ARGS=help
docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli $(HELP_ARGS)

bootstrap:
dotnet new solution
dotnet new xunit -o tests/DotnetOpenapi.Tests
dotnet sln add tests/DotnetOpenapi.Tests/DotnetOpenapi.Tests.csproj
pushd tests/DotnetOpenapi.Tests
dotnet add reference ../../src/src.csproj
popd
dotnet new gitignore --force
dotnet new tool-manifest --force
dotnet tool install Microsoft.dotnet-openapi
dotnet tool list

50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Echo.OpenAPI - ASP.NET Core 6.0 Server

A simple API to store and retrieve messages.

## Upgrade NuGet Packages

NuGet packages get frequently updated.

To upgrade this solution to the latest version of all NuGet packages, use the dotnet-outdated tool.


Install dotnet-outdated tool:

```
dotnet tool install --global dotnet-outdated-tool
```

Upgrade only to new minor versions of packages

```
dotnet outdated --upgrade --version-lock Major
```

Upgrade to all new versions of packages (more likely to include breaking API changes)

```
dotnet outdated --upgrade
```


## Run

Linux/OS X:

```
sh build.sh
```

Windows:

```
build.bat
```
## Run in Docker

```
cd src/Echo.OpenAPI
docker build -t echo.openapi .
docker run -p 5000:8080 echo.openapi
```
9 changes: 9 additions & 0 deletions build.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
:: Generated by: https://openapi-generator.tech
::

@echo off

dotnet restore src\Echo.OpenAPI
dotnet build src\Echo.OpenAPI
echo Now, run the following to start the project: dotnet run -p src\Echo.OpenAPI\Echo.OpenAPI.csproj --launch-profile web.
echo.
8 changes: 8 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
#
# Generated by: https://openapi-generator.tech
#

dotnet restore src/Echo.OpenAPI/ && \
dotnet build src/Echo.OpenAPI/ && \
echo "Now, run the following to start the project: dotnet run -p src/Echo.OpenAPI/Echo.OpenAPI.csproj --launch-profile web"
13 changes: 13 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli config-help -g aspnetcore

aspnetCoreVersion: 6.0
swashbuckleVersion: 6.4.0
packageName: Echo.OpenAPI

#useSeparateModelProject: true

# Use DateTime to model date properties even if DateOnly supported. (.net 6.0+ only) (Default: false)
useDateTimeForDate: true

# Deserialize array types to Collection<T> instead of List<T>. (Default: false)
# useCollection: true
53 changes: 53 additions & 0 deletions openapi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# https://github.com/OAI/OpenAPI-Specification/tree/main/examples/v3.0
openapi: 3.0.2

servers:
- url: http://localhost:8080

info:
title: Echo API
version: 0.0.1
description: A simple API to store and retrieve messages.

paths:
/messages:
post:
summary: Store a new message
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/Message'
responses:
'200':
description: OK
get:
summary: Search messages
parameters:
- in: query
name: query
schema:
type: string
responses:
'200':
description: OK
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Message'

components:
schemas:
Message:
type: object
properties:
id:
type: integer
message:
type: string
required:
- id
- message
22 changes: 22 additions & 0 deletions scripts/generate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash

out="${1}"

# https://github.com/OpenAPITools/openapi-generator/blob/master/docs/generators/aspnetcore.md
# docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli help config-help
# docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli config-help -g aspnetcore

spec=openapi.yaml
image=openapitools/openapi-generator-cli
docker pull -q "$image"

docker run --rm -e CSHARP_POST_PROCESS_FILE=${CSHARP_POST_PROCESS_FILE} -v "${PWD}:/local" openapitools/openapi-generator-cli generate \
--skip-validate-spec \
--enable-post-process-file \
-c /local/config.yaml \
-i /local/"$spec" \
-g aspnetcore \
-o /local/"$out"

dos2unix $(find . -type f -exec grep -I -q . {} \; -print)
pre-commit run -a
32 changes: 0 additions & 32 deletions src/Controllers/WeatherForecastController.cs

This file was deleted.

Loading

0 comments on commit ec1364e

Please sign in to comment.