jhipster openapi-client,无法生成客户端代码

时间:2020-10-15 11:57:26

标签: jhipster openapi

我想基于jhipster的openapi yaml文件生成代码,请参考https://www.jhipster.tech/doing-api-first-development/我这样做:

D:\dev\jhipster-app\openapi-demo>jhipster openapi-client
INFO! Using JHipster version installed globally
INFO! Executing jhipster:openapi-client
Welcome to the JHipster OpenApi client Sub-Generator
? Where do you want to import your OpenAPI/Swagger specification from ? From a custom specification file or endpoint
? Where is your Swagger/OpenAPI spec (URL or path) ? http://petstore.swagger.io/v2/swagger.json
? What is the unique name for your API client (please avoid using Java keywords) ? petstore
? Do you want to save this config for future reuse ? No

并提示错误:

Unable to find package.json. Reference to npm script (name: openapi-client:petstore, data:openapi-generator generate -g spring -i http://petstore.swagger.io/v2/swagger.json -p library=spring-cloud -p apiPackage=undefined.client.petstore.api -p modelPackage=undefined.client.petstore.model -p basePackage=undefined.client -p configPackage=undefined.client.petstore -p title=petstore -p artifactId=petstore -p supportingFiles=ApiKeyRequestInterceptor.java --skip-validate-spec) not added.

ERROR! Cannot read property 'endsWith' of undefined
TypeError: Cannot read property 'endsWith' of undefined
    at module.exports.getMicroserviceAppName (D:\users\dev\npm\node_modules\generator-jhipster\generators\generator-base.js:1252:66)

有人会解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

我从swagger下载示例pestore.yaml,并将其放置到现有项目的“ src / main / resources / swagger /”文件夹中,并重命名为api.yml。

并运行jhipster openapi-client:

INFO! Using JHipster version installed locally in current project's node_modules
INFO! No custom sharedOptions found within blueprint: generator-jhipster-vuejs at /mnt/program/dev/github/jhipster-app/vuedemo/node_modules/generator-jhipster-vuejs
INFO! No custom commands found within blueprint: generator-jhipster-vuejs at /mnt/program/dev/github/jhipster-app/vuedemo/node_modules/generator-jhipster-vuejs
INFO! Executing jhipster:openapi-client
Welcome to the JHipster OpenApi client Sub-Generator
? What do you want to do ? Generate a new API client
? Where do you want to import your OpenAPI/Swagger specification from ? From the api.yml spec of an existing Jhipster project
? Enter the path to the jhipster project root directory /program/github/jhipster-app/vuedemo
? What is the unique name for your API client (please avoid using Java keywords) ? petstore
? Do you want to save this config for future reuse ? No

结果似乎还可以:

Generating npm script for generating client code petstore (/program/github/jhipster-app/vuedemo/src/main/resources/swagger/api.yml)
identical .openapi-generator-ignore
identical pom.xml
identical src/main/java/com/demo/VuedemoApp.java
identical package.json
    force .yo-rc.json

Generating client for petstore

> vuedemo@0.0.0 openapi-client:petstore /mnt/program/dev/github/jhipster-app/vuedemo
> openapi-generator generate -g spring -i /program/github/jhipster-app/vuedemo/src/main/resources/swagger/api.yml -p library=spring-cloud -p apiPackage=com.demo.client.petstore.api -p modelPackage=com.demo.client.petstore.model -p basePackage=com.demo.client -p configPackage=com.demo.client.petstore -p title=petstore -p artifactId=petstore -p supportingFiles=ApiKeyRequestInterceptor.java --skip-validate-spec

Usage: openapi-generator [options] [command]

Options:
  -V, --version                      output the version number
  -d, --sdkDir <sdkDir>              sdkDir, default: process.cwd()/service
  -t, --templatePath <templatePath>  templatePath
  -t, --type <type>                  ts/js, default ts
  -c, --camelCase <camelCase>        filename style, true 为大驼峰,lower 为小驼峰
  -d, --sdkDir <sdkDir>              sdkDir, default: process.cwd()/service
  -t, --templatePath <templatePath>  templatePath
  -t, --type <type>                  ts/js, default ts
  -c, --camelCase <camelCase>        filename style, true 为大驼峰,lower 为小驼峰
  -h, --help                         output usage information

Commands:
  url <url>                          swagger2/oas3 json data url
  data <filePath>                    swagger2/oas3 json data file
  config <cfgPath>                   config path
  *
✔ Succesfully generated petstore spring client
End of openapi-client generator
INFO! Congratulations, JHipster execution is complete!

但是我找不到在src / main / webapp中生成的任何代码