[BUG] Not resolve relative path to split files in generate command
See original GitHub issueBug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- What’s the version of OpenAPI Generator used?
- Have you search for related issues/PRs?
- What’s the actual output vs expected output?
- [Optional] Bounty to sponsor the fix (example)
Description
I have a trouble in file path on $ref property.
The following my open-api schema files split. index.yml is entry point.
api-schema/
├── api
│ └── v1
│ ├── posts.yml
├── index.yml
└── schemas
└── post.yml
index.yml
openapi: "3.0.0"
info:
version: 1.0.0
title: Swagger Petstore
license:
name: MIT
servers:
- url: http://petstore.swagger.io/v1
paths:
/pets:
$ref: api/v1/posts.yml#/~1posts
api/v1/posts.yml
/posts:
get:
responses:
'200':
content:
application/json:
schema:
$ref: './../../schemas/post.yml' # Here is problem!
I use two libraries below.
How to resolve path on $ref by them are not same.
api/v1/posts.yml
# Work on redoc. Redoc resolves current path as 'api-schema/api/v1/'.
#
# However not work on openapi-generator. It resolves current path as 'api-schema/'. This is where on index.yml.
# `openapi-generator validate -i api-schema/index.yml`
# Validate of openapi-generator was success.
$ref: './../../schemas/post.yml'
# Work on openapi-generator, but not work on redoc.
$ref: 'schemas/post.yml'
I don’t know which generator or redoc the bug for.
openapi-generator version
4.2.0
OpenAPI declaration file content or url
In my case, files are split.
Command line used for generation
When $ref: './../../schemas/post.yml'
, openapi-generator fails to generate and output the following.
[main] WARN io.swagger.v3.parser.OpenAPIV3Parser - Exception while reading:
java.lang.RuntimeException: Unable to load RELATIVE ref: ./../../schemas/post.yml path: /Users/mitsuru/project/example-openapi
at io.swagger.v3.parser.util.RefUtils.readExternalRef(RefUtils.java:239)
at io.swagger.v3.parser.ResolverCache.loadRef(ResolverCache.java:119)
at io.swagger.v3.parser.processors.ExternalRefProcessor.processRefToExternalSchema(ExternalRefProcessor.java:56)
at io.swagger.v3.parser.processors.SchemaProcessor.processReferenceSchema(SchemaProcessor.java:202)
at io.swagger.v3.parser.processors.SchemaProcessor.processSchema(SchemaProcessor.java:37)
at io.swagger.v3.parser.processors.ResponseProcessor.processResponse(ResponseProcessor.java:52)
at io.swagger.v3.parser.processors.OperationProcessor.processOperation(OperationProcessor.java:67)
at io.swagger.v3.parser.processors.PathsProcessor.processPaths(PathsProcessor.java:83)
at io.swagger.v3.parser.OpenAPIResolver.resolve(OpenAPIResolver.java:49)
at io.swagger.v3.parser.OpenAPIV3Parser.readLocation(OpenAPIV3Parser.java:66)
at io.swagger.parser.OpenAPIParser.readLocation(OpenAPIParser.java:16)
at org.openapitools.codegen.config.CodegenConfigurator.toContext(CodegenConfigurator.java:451)
at org.openapitools.codegen.config.CodegenConfigurator.toClientOptInput(CodegenConfigurator.java:497)
at org.openapitools.codegen.cmd.Generate.run(Generate.java:415)
at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:61)
Caused by: java.lang.RuntimeException: Could not find ./../../schemas/post.yml on the classpath
at io.swagger.v3.parser.util.ClasspathHelper.loadFileFromClasspath(ClasspathHelper.java:31)
at io.swagger.v3.parser.util.RefUtils.readExternalRef(RefUtils.java:233)
... 14 common frames omitted
[main] WARN o.o.codegen.utils.ModelUtils - Failed to get the schema name: ./../../schemas/post.yml
[main] WARN o.o.codegen.utils.ModelUtils - Failed to get the schema name: ./../../schemas/post.yml
Steps to reproduce
see description.
Related issues/PRs
Nothing.
Suggest a fix
I know whether this is bug.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:9
- Comments:12 (2 by maintainers)
Top Results From Across the Web
How to convert absolute path to relative path in PowerShell?
I found something built in, Resolve-Path: Resolve-Path -Relative. This returns the path relative to the current location. A simple usage:
Read more >Relative and absolute paths, in the file system and on the web ...
Relative paths If you don't supply the root, it means that your path is relative. The simplest example of relative path is...
Read more >How to Split Paths with the PowerShell Split-Path Cmdlet
Learn how to split and return different elements of a path using the PowerShell Split-Path cmdlet in this tutorial.
Read more >Split-Path, Get-ChildItem – Splitting file names in PowerShell
The cmdlets Get-ChildItem and Split-Path will do the job. ... Produces an error because a relative path without -Resolve can't be resolved ...
Read more >OperatingSystem - Robot Framework
File Should Not Exist can be used to avoid overwriting existing files. Create Directory. Arguments. path. Documentation.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@nugrahawahyu
OK! I am not angry. I have thought to help you☺️ I am Japanese. I’m not good at speaking English. I am poor in expression of English🙏
Yes! I think it’s correct. I don’t know about openapi correcty😆
@mitsuru793 I’m still experiencing the issue (from master, using swagger-parser 2.0.20), care to elaborate how did you solve it?
My setup:
dir tree:
openapi.yaml:
resources/merchants/components/paths/actions.yaml:
resources/merchants/components/responses/Merchant.yaml:
resources/merchants/components/schemas/Merchant.yaml:
resources/merchants/components/schemas/Merchants.yaml:
Command line used for generation:
Output: