Hyperledger Composer:composer-rest-server生成的Open API规范存储位置及Java客户端生成咨询
Great questions! I’ve tackled this exact workflow before, so let’s break it down step by step.
1. Where is the Open API Specification stored by composer-rest-server?
First off: the composer-rest-server doesn’t write the OpenAPI Specification (OAS) to a static local file when it runs. Instead, it dynamically generates the spec on-the-fly and serves it through HTTP endpoints while the server is active.
By default, once your server is up (usually at http://localhost:3000 unless you changed the port during startup), you can access the Swagger/OpenAPI 2.0 spec at:http://<your-server-host>:<port>/swagger.json
If you configured the server to use OpenAPI 3.0 (via startup flags or config), the endpoint will be:http://<your-server-host>:<port>/openapi.json
2. How to use this spec with swagger-codegen to generate a Java client?
You’ve got two simple ways to generate your Java client—pick whichever fits your workflow better:
Option 1: Generate directly from the live API endpoint
Run the swagger-codegen command pointing straight to the spec URL. Just make sure the composer-rest-server is still running when you do this. Example command:
swagger-codegen generate -i http://localhost:3000/swagger.json -l java -o ./composer-rest-java-client
This will pull the spec dynamically and generate all the Java client code into the ./composer-rest-java-client directory.
Option 2: Download the spec first, then generate
If you want a local copy of the spec (for version control or offline use):
- Use
curlor your browser to save the spec file locally:curl http://localhost:3000/swagger.json -o composer-rest-swagger.json - Run swagger-codegen using the local file:
swagger-codegen generate -i ./composer-rest-swagger.json -l java -o ./composer-rest-java-client
A quick heads-up: The spec is tailored to your specific Hyperledger Composer business network, so make sure the server is running against the correct network when you fetch the spec—otherwise, the generated client won’t match your API endpoints.
内容的提问来源于stack exchange,提问作者blahblahblah

