File tree Expand file tree Collapse file tree 4 files changed +46
-4
lines changed
spotify-web-api-generator-open-api
src/main/java/de/sonallux/spotify/generator/openapi Expand file tree Collapse file tree 4 files changed +46
-4
lines changed Original file line number Diff line number Diff line change 11openapi : 3.0.1
22info :
33 title : Spotify Web API
4- version : 0.0.1
4+ version : 2021.3.31
55externalDocs :
66 description : Find more info on the official Spotify Web API Reference
77 url : https://developer.spotify.com/documentation/web-api/reference
Original file line number Diff line number Diff line change @@ -110,13 +110,13 @@ public String[] getVersion() throws Exception {
110110 var title = get (attributes , "Implementation-Title" );
111111 if (IMPLEMENTATION_TITLE .equals (title )) {
112112 var version = get (attributes , "Implementation-Version" );
113- return new String [] { title + " version \" " + version + " \" " };
113+ return new String [] { IMPLEMENTATION_TITLE , version . toString () };
114114 }
115115 } catch (IOException e ) {
116116 return new String [] { "Unable to read manifest from " + url + ": " + e };
117117 }
118118 }
119- return new String [] { IMPLEMENTATION_TITLE + " version \" unknown\" " };
119+ return new String [] { IMPLEMENTATION_TITLE , " unknown" };
120120 }
121121
122122 private static Object get (Attributes attributes , String key ) {
Original file line number Diff line number Diff line change @@ -44,7 +44,7 @@ public OpenAPI generate(SpotifyWebApi apiDocumentation) {
4444 )
4545 .info (new Info ()
4646 .title ("Spotify Web API" )
47- .version ("0.0.1" )
47+ .version (VersionProvider . getVersion () )
4848 )
4949 .servers (List .of (new Server ().url (apiDocumentation .getEndpointUrl ())))
5050 .components (new Components ()
Original file line number Diff line number Diff line change 1+ package de .sonallux .spotify .generator .openapi ;
2+
3+ import java .io .IOException ;
4+ import java .nio .file .Files ;
5+ import java .nio .file .Path ;
6+ import java .util .regex .Pattern ;
7+
8+ public class VersionProvider {
9+ private static final Pattern VERSION_PATTERN = Pattern .compile ("<version>([0-9.]+)</version>" );
10+
11+ public static String getVersion () {
12+ try {
13+ var versions = new CLI .ManifestVersionProvider ().getVersion ();
14+ if (!"unknown" .equals (versions [1 ])) {
15+ return versions [1 ];
16+ }
17+ } catch (Exception ignore ) {
18+ }
19+
20+ try {
21+ var lines = Files .readAllLines (Path .of ("./pom.xml" ));
22+ var versionLine = -1 ;
23+ for (int i = 0 ; i < lines .size (); i ++) {
24+ if ("<artifactId>spotify-web-api-parent</artifactId>" .equals (lines .get (i ).trim ())) {
25+ versionLine = i + 1 ;
26+ break ;
27+ }
28+ }
29+
30+ if (versionLine != -1 ) {
31+ var matcher = VERSION_PATTERN .matcher (lines .get (versionLine ).trim ());
32+ if (matcher .matches ()) {
33+ return matcher .group (1 );
34+ }
35+ }
36+ }
37+ catch (IOException e ) {
38+ e .printStackTrace ();
39+ }
40+ return "unknown" ;
41+ }
42+ }
You can’t perform that action at this time.
0 commit comments