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

[jaxrs-cfx][server] bin/jaxrs-cxf-petstore-server.sh does not generate required files #451

Closed
grokify opened this issue Jul 4, 2018 · 2 comments

Comments

@grokify
Copy link
Member

grokify commented Jul 4, 2018

Description

When adding new tests, builds fail because new endpoints are not added to samples/server/petstore/jaxrs-cxf

This happens because many files exist and thus are not overwritten.

This is generated by bin/jaxrs-cxf-petstore-server.sh which is run by all three of the following:

bin/jaxrs-cxf-petstore-server.sh
bin/java-jaxrs-petstore-server-all.sh
bin/utils/ensure-up-to-date

An example of this is here:

#382 (comment)

openapi-generator version

3.0.3

OpenAPI declaration file content or url

https://github.com/grokify/openapi-generator/blob/go/client/fix/file-for-schema-definition-name/modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml

Command line used for generation

Any of the following:

$ bin/jaxrs-cxf-petstore-server.sh
$ bin/java-jaxrs-petstore-server-all.sh
$ bin/utils/ensure-up-to-date
Steps to reproduce

Generate jaxrs-cxf sample with new endpoint and commit.

Here is an example:

https://circleci.com/gh/grokify/openapi-generator/38

[ERROR] COMPILATION ERROR : 
[ERROR] /home/circleci/OpenAPITools/openapi-generator/samples/server/petstore/jaxrs-cxf/src/main/java/org/openapitools/api/impl/FakeApiServiceImpl.java:[32,8] org.openapitools.api.impl.FakeApiServiceImpl is not abstract and does not override abstract method testBodyWithFileSchema(org.openapitools.model.FileSchemaTestClass) in org.openapitools.api.FakeApi
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project openapi-cxf-server: Compilation failure
[ERROR] /home/circleci/OpenAPITools/openapi-generator/samples/server/petstore/jaxrs-cxf/src/main/java/org/openapitools/api/impl/FakeApiServiceImpl.java:[32,8] org.openapitools.api.impl.FakeApiServiceImpl is not abstract and does not override abstract method testBodyWithFileSchema(org.openapitools.model.FileSchemaTestClass) in org.openapitools.api.FakeApi
[ERROR] -> [Help 1]
Related issues/PRs

This has been experienced when adding new endpoints to the Petstore spec for testing.

Suggest a fix/enhancement

A simple fix is to remove the output directory first as described below. This approach has worked for me twice now, however, it seems a more generic solution may be to use .openapi-generator-ignore and replace writeOptional. I've taken a quick look and will examine more.

rm -rf samples/server/petstore/jaxrs-cxf
diff --git a/bin/jaxrs-cxf-petstore-server.sh b/bin/jaxrs-cxf-petstore-server.sh
index 6846f2e..0fc6564 100755
--- a/bin/jaxrs-cxf-petstore-server.sh
+++ b/bin/jaxrs-cxf-petstore-server.sh
@@ -25,6 +25,8 @@ then
   mvn -B clean package
 fi
 
+rm -rf samples/server/petstore/jaxrs-cxf
+
 # if you've executed sbt assembly previously it will use that instead.
 export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
 ags="generate -t modules/openapi-generator/src/main/resources/JavaJaxRS/cxf -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g jaxrs-cxf -o samples/server/petstore/jaxrs-cxf -DhideGenerationTimestamp=true --additional-properties serverPort=8082 $@"
@jmini
Copy link
Member

jmini commented Jul 4, 2018

Thank you a lot for this investigation.


In my opinion the generator works as expected, because in a real project it is a good practice to split:

src/gen/java: generated code that you regenerate every time again.
src/main/java: code containing your implementation, your business logic. You often get some stubs with the initial project, but then you prefer get compile error indicating that you need to change something, rather than having your code lost after a generation.

This pattern is discussed in #426


For our samples/ folder this is not ideal.

My opinion/vision is that everything inside samples/ could be deleted and recreated by the run of the bin/*.sh scripts. We are not exactly there yet (it is a case-by-case analysis).

I have seen that other *.sh scripts also delete part of the generated code before the run. One example:

echo "Removing files and folders under samples/client/petstore/java/feign/src/main"
rm -rf samples/client/petstore/java/feign/src/main
find samples/client/petstore/java/feign -maxdepth 1 -type f ! -name "README.md" -exec rm {} +

In my opinion it is OK to delete stuff in bin/jaxrs-cxf-petstore-server.sh (I did not check it in detail).

@grokify
Copy link
Member Author

grokify commented Jul 4, 2018

@jmini Thanks for the reply. It's useful to understand the reasoning for this.

I agree it would be nice to delete the entire samples/ directory when creating new samples with the bin/*.sh scripts. It keeps the output cleaner and more up to date. Earlier, I had expected deleting the entire samples/ directory would work and tried it but it didn't yield the desired results. Getting back to a working state took a bit of investigation because a number of files were covered in deep .gitignore files like samples/client/petstore/clojure/.gitignore.

I've created a PR for review given your comment above: #452

@jmini jmini closed this as completed in #452 Jul 5, 2018
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

No branches or pull requests

2 participants