Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KTOR-7748 Generate a server project from OpenAPI specification #34

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

Stexxe
Copy link
Contributor

@Stexxe Stexxe commented Nov 14, 2024

https://youtrack.jetbrains.com/issue/KTOR-7748

How to use

Generates a server project using the given OpenAPI specification.
To generate the project, issue the following command in the current working directory:

ktor openapi spec.yml

To generate the project in a different directory, use the -o or --output flag:

ktor openapi --output=/path/to/dir openapi.yml

How it works

It downloads a JAR with the OpenAPI CLI Generator utility, saves it into a temp directory, and then executes it as an external command to generate a project. To execute the external command, it tries to find a JDK and downloads one if it cannot be found.
The downloaded JAR is cached in the ~/.ktor/temp directory forever until the version of the OpenAPI generator is changed in the source code.

Here is a list of issues related to the generated code:

@Stexxe Stexxe requested review from e5l and bjhham November 14, 2024 14:38
@Stexxe Stexxe changed the title KTOR-7748 Generate a server project with OpenAPI specification KTOR-7748 Generate a server project from OpenAPI specification Nov 14, 2024
@e5l
Copy link
Member

e5l commented Nov 15, 2024

@antonarhipov, could you also check?

@e5l e5l requested a review from antonarhipov November 15, 2024 08:01
@e5l
Copy link
Member

e5l commented Nov 15, 2024

@vnikolova, please check the docs

@e5l e5l requested review from vnikolova and removed request for e5l November 15, 2024 08:01
@e5l
Copy link
Member

e5l commented Nov 15, 2024

@Stexxe, thanks for the PR.
Could you tell me if you thought how we would generate openAPI clients for ktor clients?

@Stexxe Stexxe force-pushed the stexxe/openapi-generate-project branch from b389707 to 4987a45 Compare November 18, 2024 10:07
Copy link

@vnikolova vnikolova left a comment

Choose a reason for hiding this comment

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

Looks good! A few grammar and punctuation edits in my comments.

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
internal/app/i18n/bundle.en.go Outdated Show resolved Hide resolved
internal/app/i18n/bundle.en.go Outdated Show resolved Hide resolved
internal/app/i18n/bundle.en.go Outdated Show resolved Hide resolved
internal/app/i18n/bundle.en.go Outdated Show resolved Hide resolved
internal/app/i18n/bundle.en.go Outdated Show resolved Hide resolved
internal/app/i18n/bundle.en.go Outdated Show resolved Hide resolved
internal/app/i18n/bundle.en.go Outdated Show resolved Hide resolved
@Stexxe Stexxe requested a review from vnikolova November 21, 2024 10:20
@antonarhipov
Copy link

I tried this:

anton@macbook-pro tmp % ./ktor-cli/ktor openapi -o ktor-project openapi.yml
Error downloading OpenAPI utility. Please try again later.
For more details, see the log: /Users/anton/.ktor/run.log.

anton@macbook-pro tmp % less /Users/anton/.ktor/run.log:

2024/11/22 18:25:34 16: fetch OpenAPI JAR: unexpected response status 404 from the server:

<title>404 - Path /org/openapitools/openapi-generator-cli/7.10.0-SNAPSHOT/openapi-generator-cli-7.10.0-20241106.082455-66.jar not found in local storage of repository "Snapshots" [id=snapshots]</title> ...

@Stexxe
Copy link
Contributor Author

Stexxe commented Nov 25, 2024

I tried this:

anton@macbook-pro tmp % ./ktor-cli/ktor openapi -o ktor-project openapi.yml Error downloading OpenAPI utility. Please try again later. For more details, see the log: /Users/anton/.ktor/run.log.

anton@macbook-pro tmp % less /Users/anton/.ktor/run.log:

2024/11/22 18:25:34 16: fetch OpenAPI JAR: unexpected response status 404 from the server:

<title>404 - Path /org/openapitools/openapi-generator-cli/7.10.0-SNAPSHOT/openapi-generator-cli-7.10.0-20241106.082455-66.jar not found in local storage of repository "Snapshots" [id=snapshots]</title> ...

That's strange. I cannot reproduce it at the moment. Can you please try again?

@Stexxe Stexxe force-pushed the stexxe/openapi-generate-project branch from f87d1fe to 54b5ea0 Compare November 25, 2024 10:38
@Stexxe Stexxe requested a review from e5l December 3, 2024 16:09
DialContext: func(_ context.Context, network, addr string) (net.Conn, error) {
return net.DialTimeout(network, addr, 5*time.Second)
},
TLSHandshakeTimeout: 10 * time.Second,
Copy link
Member

Choose a reason for hiding this comment

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

Please consider extracting constants

cmd/ktor/main.go Show resolved Hide resolved
return e
}

return "https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/7.10.0/openapi-generator-cli-7.10.0.jar"
Copy link
Member

Choose a reason for hiding this comment

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

we might also want to have a property for version

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you mean by property?

Copy link
Member

Choose a reason for hiding this comment

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

env variable. URL is hard to use to change just version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants