问题
I am generating code for typescript-angular
with the openapi-generator-maven-plugin like this:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<build>
<plugins>
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>4.2.0</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/../my_server/openapi.json</inputSpec>
<generatorName>typescript-angular</generatorName>
<output>${project.basedir}</output>
<npmName>myClientRest</npmName>
<npmRepository>http://localhost:8444/repository/npm-releases/</npmRepository>
<providedInRoot>true</providedInRoot>
<apiModulePrefix>my</apiModulePrefix>
<stringEnums>true</stringEnums>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
What I am missing now is a package.json
file so that I could do a npm install
.
From some older swagger examples it looks like with the swagger plugin a package.json
file was generated.
So my question is why is the package.json
file not generated and what could I do to get one?
The output of the generator run looks ok to me:
[INFO] --- openapi-generator-maven-plugin:4.2.0:generate (default) @ client ---
[INFO] OpenAPI Generator: typescript-angular (client)
[INFO] Generator 'typescript-angular' is considered stable.
[INFO] Hint: Environment variable 'TS_POST_PROCESS_FILE' (optional) not defined. E.g. to format the source code, please try 'export TS_POST_PROCESS_FILE="/usr/local/bin/prettier --write"' (Linux/Mac)
[INFO] Note: To enable file post-processing, 'enablePostProcessFile' must be set to
true
(--enable-post-process-file for CLI).[INFO] generating code for Angular 8.0.0 ...
[INFO] (you can select the angular version by setting the additionalProperty ngVersion)
[INFO] writing file C:\my-client-rest\api\default.service.ts
[INFO] writing file C:\my-client-rest\model\models.ts
[INFO] writing file C:\my-client-rest\api\api.ts
[INFO] writing file C:\my-client-rest\index.ts
[INFO] writing file C:\my-client-rest\api.module.ts
[INFO] writing file C:\my-client-rest\configuration.ts
[INFO] writing file C:\my-client-rest\variables.ts
[INFO] writing file C:\my-client-rest\encoder.ts
[INFO] writing file C:\my-client-rest.gitignore
[INFO] writing file C:\my-client-rest\git_push.sh
[INFO] writing file C:\my-client-rest\README.md
[INFO] writing file C:\my-client-rest.openapi-generator\VERSION
回答1:
Looks like the description of the plugin is not very clear (at least to me), because it seems that:
<configuration>
<npmName>myClientRest</npmName>
</configuration>
is wrong and should be replaced with:
<configuration>
<additionalProperties>npmName=myClientRest</additionalProperties>
</configuration>
or with:
<configuration>
<configOptions>
<npmName>tmsClientRest</npmName>
</configOptions>
</configuration>
to make the generation of package.json and tsconfig.json work.
So my original example should be changed to:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<build>
<plugins>
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>4.2.1</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/../my_server/openapi.json</inputSpec>
<generatorName>typescript-angular</generatorName>
<output>${project.basedir}</output>
<configOptions>
<npmName>tmsClientRest</npmName>
<npmRepository>http://www.test-tms-archiv-net.de:8444/repository/npm-releases/</npmRepository>
<providedInRoot>true</providedInRoot>
<apiModulePrefix>tms</apiModulePrefix>
<stringEnums>true</stringEnums>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
来源:https://stackoverflow.com/questions/58952134/why-does-openapi-generator-not-create-a-package-json-with-typescript-angular