Keith Marsh
Keith Marsh

Reputation: 175

Getting the openapi spec from a library I depend on

I have multiple apps that used the same datatypes. I duplicated these in each OpenAPI spec. Boo.

I have seen the light and pulled these types to a library, and they are marked as imported in the apps. The library has it's own openapi spec for the data types, and it is published to a maven repository.

When I build one of my dependent apps, I need to get hold of the openapi spec for the library, so I can resolve the $refs to these datatypes. I'll replace the refs to the data types with Remote References to the datatypes in the library spec. The build of an app cannot rely on the build of the library being present.

I am attaching the openapi30.yaml as an artifact on the library and I can see the file in the repo and download it manually.

publishing {
    publications {
        mavenJava(MavenPublication) {
            from components.java
            artifact 'openapi30.yaml'

        }
    }
}

And the respository shows

Am I approaching this problem correctly? If I am, how does the build.gradle of my apps retrieve and access this file? Looking in the .gradle/caches it only pulls down the jar, pom and .module files, not my spec.

Upvotes: 1

Views: 1034

Answers (1)

Keith Marsh
Keith Marsh

Reputation: 175

In the library, attach your spec with a classifier

publishing {
    publications {
        mavenJava(MavenPublication) {
            from components.java
            artifact source: 'openapi30.yaml', classifier: 'openapi', extension: 'yaml'
        }
    }
}

In the consuming app, add a configuration and dependency

configurations {
    apisource
}

dependencies {
    apisource group: 'com.xxx.yyy', name: 'lib', version: '0.1.2', classifier: 'openapi', ext: 'yaml'
}

In a task, you can reference the file downloaded using

configurations.apisource.asPath

If there's a better way than this, please post an alternative answer.

Upvotes: 3

Related Questions