Skip to content

Generate merge spec#14387

Merged
wing328 merged 1 commit intoOpenAPITools:masterfrom
borsch:generate-merged-spec
Feb 17, 2023
Merged

Generate merge spec#14387
wing328 merged 1 commit intoOpenAPITools:masterfrom
borsch:generate-merged-spec

Conversation

@borsch
Copy link
Copy Markdown
Member

@borsch borsch commented Jan 5, 2023

Implementation for #3981

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh
    ./bin/utils/export_docs_generators.sh
    
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    For Windows users, please run the script in Git BASH.
  • File the PR against the correct branch: master (6.3.0) (minor release - breaking changes with fallbacks), 7.0.x (breaking changes without fallbacks)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

@borsch borsch requested a review from jimschubert as a code owner January 5, 2023 16:56
@borsch
Copy link
Copy Markdown
Member Author

borsch commented Jan 5, 2023

@wing328 (2015/07) ❤️
@jimschubert (2016/05) ❤️
@cbornet (2016/05)
@jmini (2018/04) ❤️
@etherealjoy (2019/06)
@spacether (2020/05) ❤️

@borsch borsch force-pushed the generate-merged-spec branch 2 times, most recently from 18eb87e to e40ae08 Compare January 13, 2023 14:31
@borsch borsch force-pushed the generate-merged-spec branch 3 times, most recently from 2a10be3 to df0d106 Compare January 31, 2023 12:59
@borsch
Copy link
Copy Markdown
Member Author

borsch commented Jan 31, 2023

@wing328 could you please review once you have a time?

@wing328
Copy link
Copy Markdown
Member

wing328 commented Feb 10, 2023

@borsch thanks for the PR as always.

do we need to update openapi-generator-cli module to support the new option as well?

currently, the users need to use a script or something to loop through all the spec in a folder in order to achieve the same ,right?

@borsch
Copy link
Copy Markdown
Member Author

borsch commented Feb 10, 2023

@borsch thanks for the PR as always.

do we need to update openapi-generator-cli module to support the new option as well?

currently, the users need to use a script or something to loop through all the spec in a folder in order to achieve the same ,right?

Thanks. Sure, will add CLI support.
Regarding workaround - personally I use small bash script to handle this, but this is a little bit annoying to move it to each and every service, where generator is used

#!/bin/bash
API_HEADER="openapi: '3.0.0'
info:
    description: Merge description
    version: '1.0'
    title: Merge title

servers:
  - url: https://localhst:8079

paths:\n"
printf "%s${API_HEADER}" >> "src/main/resources/contract/_index_auto.yaml"
grep --exclude='*index*' -E '^ */' "src/main/resources/contract"/* | sort | while read -r line; do
  path=$(echo "$line" | awk '{print $2}')
  fileName=$(echo "$line" | awk '{print $1}' | awk -F "/" '{print $NF}' | sed 's/:*$//g')
  # shellcheck disable=SC2001
  ref=$(echo "${path//\//~1}" | sed 's/:*$//g')

  printf "
  %s$path
    \$ref: './%s$fileName#/paths/%s$ref'\n" >> "src/main/resources/contract/_index_auto.yaml"
done
  • maven plugin that will execute above script
                           <plugin>
				<groupId>org.codehaus.mojo</groupId>
				<artifactId>exec-maven-plugin</artifactId>
				<executions>
					<execution>
						<id>generate-openapi-common-file</id>
						<goals>
							<goal>exec</goal>
						</goals>
						<phase>generate-resources</phase>
						<configuration>
							<executable>bash</executable>
							<arguments>
								<argument>generate_open_api.sh</argument>
							</arguments>
						</configuration>
					</execution>
				</executions>
			</plugin>

@borsch borsch force-pushed the generate-merged-spec branch 2 times, most recently from b6cdf1b to 3fadbbb Compare February 11, 2023 10:58
@borsch
Copy link
Copy Markdown
Member Author

borsch commented Feb 11, 2023

@wing328 I've applied change to CLI module

@wing328
Copy link
Copy Markdown
Member

wing328 commented Feb 16, 2023

i just merged a PR with updated samples. can you merge the latest master into your branch?

@wing328
Copy link
Copy Markdown
Member

wing328 commented Feb 16, 2023

Did some tests and the result is good 👍

I will merge when all CI tests pass.

Thanks again for the PR.

@borsch borsch force-pushed the generate-merged-spec branch from 743172e to 6dd606d Compare February 16, 2023 15:42
@wing328 wing328 merged commit 2bc963f into OpenAPITools:master Feb 17, 2023
@borsch borsch deleted the generate-merged-spec branch February 17, 2023 07:53
@heyline
Copy link
Copy Markdown

heyline commented May 13, 2024

Hello, I encountered several problems when using inputSpecRootDirectory and would like to ask for advice.

  1. If I have a secondary directory, like openapi/path/configuration.yml , I find that merge.yml generates the wrong path, the correct path is
  /connectors:
    $ref: "./path/configuration.yml#/paths/~1configuration"

but i got

  /configuration:
    $ref: "./path\\configuration.yml#/paths/~1configuration"
  1. The generated file does not contain my tags.

  2. How do I change this, 8080 is not my port.

图片

"version", "1.0.0"
));
map.put("servers", Collections.singleton(
ImmutableMap.of("url", "http://localhost:8080")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, why not include the servers array from one or more of the input files?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have abandoned this plugin and use redocly

tasks.register<Exec>("mergeOpenApiSpecs") {
    val specs = projectDir.resolve("src/main/resources/openapi").listFiles()!!.filter { it.name != "merged.yml" }
        .map { it.name }.toTypedArray()
    commandLine(
        "docker",
        "run",
        "--rm",
        "-v",
        "${projectDir.resolve("src/main/resources/openapi").absolutePath}:/spec",
        "redocly/cli:1.12.2",
        "join",
        "--without-x-tag-groups",
        *specs,
        "-o",
        "merged.yml"
    )
}

Copy link
Copy Markdown

@gd-scalemem gd-scalemem Aug 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing the merge explicitly is not that hard and offers more flexibility, but I guess it's useful to have a built-in one that does the job for many use cases. @borsch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants