Skip to content

Commit 17d7b98

Browse files
authored
Spotify Web API reference update (#112)
* Automated update from Spotify Web API reference * Fix scopes
1 parent 7a53387 commit 17d7b98

21 files changed

+918
-2181
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>de.sonallux.spotify</groupId>
88
<artifactId>spotify-web-api-parent</artifactId>
9-
<version>2021.8.28</version>
9+
<version>2021.10.17</version>
1010
<packaging>pom</packaging>
1111

1212
<name>spotify-web-api-parent</name>

spotify-web-api-core/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
<parent>
88
<groupId>de.sonallux.spotify</groupId>
99
<artifactId>spotify-web-api-parent</artifactId>
10-
<version>2021.8.28</version>
10+
<version>2021.10.17</version>
1111
<relativePath>../pom.xml</relativePath>
1212
</parent>
1313

1414
<artifactId>spotify-web-api-core</artifactId>
15-
<version>2021.8.28</version>
15+
<version>2021.10.17</version>
1616
<packaging>jar</packaging>
1717

1818
<name>spotify-web-api-core</name>

spotify-web-api-core/src/main/java/de/sonallux/spotify/core/model/SpotifyWebApiEndpoint.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ public SpotifyWebApiEndpoint(@NonNull String id, String name, String link, Strin
3838
this(id, name, link, description, httpMethod, path, parameters, requestBody, responseDescription, scopes, notes, new ArrayList<>());
3939
}
4040

41+
public SpotifyWebApiEndpoint addScope(String scope) {
42+
this.scopes.add(scope);
43+
return this;
44+
}
45+
4146
@Getter
4247
@Setter
4348
@NoArgsConstructor

spotify-web-api-core/src/main/resources/spotify-web-api.yml

Lines changed: 367 additions & 996 deletions
Large diffs are not rendered by default.

spotify-web-api-generator-open-api/pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
<parent>
88
<groupId>de.sonallux.spotify</groupId>
99
<artifactId>spotify-web-api-parent</artifactId>
10-
<version>2021.8.28</version>
10+
<version>2021.10.17</version>
1111
<relativePath>../pom.xml</relativePath>
1212
</parent>
1313

1414
<artifactId>spotify-web-api-generator-open-api</artifactId>
15-
<version>2021.8.28</version>
15+
<version>2021.10.17</version>
1616
<packaging>jar</packaging>
1717

1818
<name>spotify-web-api-generator-open-api</name>
@@ -31,7 +31,7 @@
3131
<dependency>
3232
<groupId>de.sonallux.spotify</groupId>
3333
<artifactId>spotify-web-api-core</artifactId>
34-
<version>2021.8.28</version>
34+
<version>2021.10.17</version>
3535
</dependency>
3636
<dependency>
3737
<groupId>com.fasterxml.jackson.core</groupId>

spotify-web-api-generator-open-api/spotify-web-api-openapi.yml

Lines changed: 377 additions & 1096 deletions
Large diffs are not rendered by default.

spotify-web-api-parser/pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
<parent>
88
<groupId>de.sonallux.spotify</groupId>
99
<artifactId>spotify-web-api-parent</artifactId>
10-
<version>2021.8.28</version>
10+
<version>2021.10.17</version>
1111
<relativePath>../pom.xml</relativePath>
1212
</parent>
1313

1414
<artifactId>spotify-web-api-parser</artifactId>
15-
<version>2021.8.28</version>
15+
<version>2021.10.17</version>
1616
<packaging>jar</packaging>
1717

1818
<name>spotify-web-api-parser</name>
@@ -30,7 +30,7 @@
3030
<dependency>
3131
<groupId>de.sonallux.spotify</groupId>
3232
<artifactId>spotify-web-api-core</artifactId>
33-
<version>2021.8.28</version>
33+
<version>2021.10.17</version>
3434
</dependency>
3535
<dependency>
3636
<groupId>org.jsoup</groupId>

spotify-web-api-parser/src/main/java/de/sonallux/spotify/parser/ApiEndpointParser.java

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ private SpotifyWebApiEndpoint parseSpotifyApiEndpoint(Elements elements) throws
153153

154154
var requestBody = extractRequestBody(parameters);
155155

156-
var scopes = extractScopes(id, parameters);
156+
var scopes = new ArrayList<String>();
157157

158158
return new SpotifyWebApiEndpoint(id, name, link, description, httpMethod, path, parameters, requestBody, responseDescription, scopes, notes);
159159
}
@@ -225,20 +225,4 @@ private String parseNotes(List<Element> elements) {
225225
elements.removeIf(e -> "Try in our Web Console".equalsIgnoreCase(e.text()));
226226
return Html2Markdown.convert(elements);
227227
}
228-
229-
private List<String> extractScopes(String id, List<SpotifyWebApiEndpoint.Parameter> parameters) {
230-
var authHeader = parameters.stream().filter(p -> "Authorization".equals(p.getName())).findFirst();
231-
if (authHeader.isEmpty()) {
232-
log.warn("Endpoint {} has no Authorization header", id);
233-
return new ArrayList<>();
234-
}
235-
236-
var codePattern = Pattern.compile("`([a-z-]+)`");
237-
var matcher = codePattern.matcher(authHeader.get().getDescription());
238-
var scopes = new ArrayList<String>();
239-
while (matcher.find()) {
240-
scopes.add(matcher.group(1));
241-
}
242-
return scopes;
243-
}
244228
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package de.sonallux.spotify.parser;
2+
3+
import de.sonallux.spotify.core.model.*;
4+
import lombok.AccessLevel;
5+
import lombok.RequiredArgsConstructor;
6+
7+
import java.util.Comparator;
8+
import java.util.Map;
9+
import java.util.stream.Collectors;
10+
11+
/**
12+
* Injects the scopes from the {@link de.sonallux.spotify.core.model.SpotifyAuthorizationScopes} into the scopes field of
13+
* {@link de.sonallux.spotify.core.model.SpotifyWebApiEndpoint}
14+
*/
15+
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
16+
class ScopeInjector {
17+
private static final String API_NAME = "web-api";
18+
19+
private final Map<String, SpotifyWebApiEndpoint> endpointMap;
20+
21+
static void run(SpotifyWebApi spotifyWebApi) {
22+
var endpointMap = spotifyWebApi.getCategoryList().stream()
23+
.flatMap(category -> category.getEndpointList().stream())
24+
.collect(Collectors.toMap(SpotifyWebApiEndpoint::getId, e -> e));
25+
26+
var scopeInjector = new ScopeInjector(endpointMap);
27+
scopeInjector.injectScopes(spotifyWebApi.getScopes());
28+
}
29+
30+
void injectScopes(SpotifyAuthorizationScopes scopes) {
31+
scopes.getScopeList().stream()
32+
.sorted(Comparator.comparing(SpotifyScope::getId))
33+
.forEach(this::injectScope);
34+
}
35+
36+
private void injectScope(SpotifyScope scope) {
37+
scope.getEndpoints().stream()
38+
.filter(endpointLink -> API_NAME.equals(endpointLink.getApi()))
39+
.map(SpotifyScope.EndpointLink::getEndpoint)
40+
.map(endpointMap::get)
41+
.forEach(endpoint -> endpoint.addScope(scope.getId()));
42+
}
43+
}

spotify-web-api-parser/src/main/java/de/sonallux/spotify/parser/ScopeValidator.java

Lines changed: 0 additions & 46 deletions
This file was deleted.

0 commit comments

Comments
 (0)