使用命令行参数 --generator-parameter="generate_client=false"
来禁用生成客户端。之后,手动创建DTO并生成对应的typescript接口。
示例代码:
#禁用生成客户端
$ php bin/console api:openapi:export --output=spec.yaml
$ php bin/console api:swagger:export --output=spec.yaml --yaml
$ npx @openapitools/openapi-generator-cli generate -i spec.yaml -g typescript-fetch --generator-parameter="generate_client=false" --additional-properties=supportsES6=true,typescriptThreePlus=true,withInterfaces=true,withTSTypePrefix=true,withMappedTypes=true -o ./src/ApiPlatform --skip-validate-spec
#手动生成命令
$ php bin/console generator:command app:generate-dto --entity=App\\Entity\\MyEntity --target=App\\Dto\\MyEntityDto
$ php bin/console make:class App\\Dto\\MyEntityDto
参考链接:https://github.com/api-platform/core/issues/2721#issuecomment-572381820