-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Migrate azure-search-documents to TypeSpec #47819
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
alzimmermsft
merged 20 commits into
Azure:main
from
alzimmermsft:AzSearch_MigrateToTypeSpec
Feb 10, 2026
Merged
Changes from 17 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
70f686a
Initial regeneration using TypeSpec
alzimmermsft 9a50ce8
Working on migrating tests, adding back convenience APIs that are bei…
alzimmermsft 2f8bd79
Complete most of the migration
alzimmermsft 9b6af1c
Additional work
alzimmermsft 38aa0ac
Stable point before tests
alzimmermsft 0f0bace
Newer TypeSpec SHA
alzimmermsft e8f3086
Add back SearchAudience support
alzimmermsft b5e89a5
Last changes before testing
alzimmermsft 81d11ed
Merge branch 'main' into AzSearch_MigrateToTypeSpec
alzimmermsft 70b62b3
Rerecord tests and misc fixes along the way
alzimmermsft b72b976
Fix a few recordings and stress tests
alzimmermsft 5faebbb
Merge in main
alzimmermsft 75e6ac1
Fix a few recordings and linting
alzimmermsft 540e39d
Few more fixes
alzimmermsft 9fbda57
Another round of recording
alzimmermsft 00735e9
Rerun TypeSpec codegen
alzimmermsft c0bc08b
Remove errant import
alzimmermsft 913a99f
Cleanup APIs
alzimmermsft 5e01823
Regeneration
alzimmermsft dc48cc5
Clean up linting
alzimmermsft File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| # Release History | ||
|
|
||
| ## 11.9.0-beta.2 (Unreleased) | ||
| ## 12.0.0-beta.1 (Unreleased) | ||
|
|
||
| ### Features Added | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
88 changes: 88 additions & 0 deletions
88
sdk/search/azure-search-documents/customizations/src/main/java/SearchCustomizations.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| import com.azure.autorest.customization.ClassCustomization; | ||
| import com.azure.autorest.customization.Customization; | ||
| import com.azure.autorest.customization.LibraryCustomization; | ||
| import com.azure.autorest.customization.PackageCustomization; | ||
| import com.github.javaparser.StaticJavaParser; | ||
| import com.github.javaparser.ast.Modifier; | ||
| import com.github.javaparser.ast.NodeList; | ||
| import com.github.javaparser.ast.body.BodyDeclaration; | ||
| import com.github.javaparser.ast.body.FieldDeclaration; | ||
| import com.github.javaparser.ast.body.MethodDeclaration; | ||
| import com.github.javaparser.ast.body.VariableDeclarator; | ||
| import com.github.javaparser.ast.nodeTypes.NodeWithMembers; | ||
| import org.slf4j.Logger; | ||
|
|
||
| import java.util.Arrays; | ||
|
|
||
| /** | ||
| * Contains customizations for Azure AI Search code generation. | ||
| */ | ||
| public class SearchCustomizations extends Customization { | ||
| @Override | ||
| public void customize(LibraryCustomization libraryCustomization, Logger logger) { | ||
| PackageCustomization documents = libraryCustomization.getPackage("com.azure.search.documents"); | ||
| PackageCustomization indexes = libraryCustomization.getPackage("com.azure.search.documents.indexes"); | ||
| PackageCustomization knowledge = libraryCustomization.getPackage("com.azure.search.documents.knowledgebases"); | ||
|
|
||
| hideGeneratedSearchApis(documents); | ||
|
|
||
| addSearchAudienceScopeHandling(documents.getClass("SearchClientBuilder"), logger); | ||
| addSearchAudienceScopeHandling(indexes.getClass("SearchIndexClientBuilder"), logger); | ||
| addSearchAudienceScopeHandling(indexes.getClass("SearchIndexerClientBuilder"), logger); | ||
| addSearchAudienceScopeHandling(knowledge.getClass("KnowledgeBaseRetrievalClientBuilder"), logger); | ||
| } | ||
|
|
||
| // Weird quirk in the Java generator where SearchOptions is inferred from the parameters of searchPost in TypeSpec, | ||
| // where that class doesn't actually exist in TypeSpec so it requires making the searchPost API public which we | ||
| // don't want. This customization hides the searchPost APIs that were exposed. | ||
| private static void hideGeneratedSearchApis(PackageCustomization documents) { | ||
| for (String className : Arrays.asList("SearchClient", "SearchAsyncClient")) { | ||
| documents.getClass(className).customizeAst(ast -> ast.getClassByName(className).ifPresent(clazz -> { | ||
| clazz.getMethodsByName("searchWithResponse") | ||
| .stream() | ||
| .filter(method -> method.isAnnotationPresent("Generated")) | ||
| .forEach(MethodDeclaration::setModifiers); | ||
|
|
||
| clazz.getMethodsByName("autocompleteWithResponse") | ||
| .stream() | ||
| .filter(method -> method.isAnnotationPresent("Generated")) | ||
| .forEach(MethodDeclaration::setModifiers); | ||
|
|
||
| clazz.getMethodsByName("suggestWithResponse") | ||
| .stream() | ||
| .filter(method -> method.isAnnotationPresent("Generated")) | ||
| .forEach(MethodDeclaration::setModifiers); | ||
| })); | ||
| } | ||
| } | ||
|
|
||
| // Adds SearchAudience handling to generated builders. This is a temporary fix until | ||
| // https://github.com/microsoft/typespec/issues/9458 is addressed. | ||
| private static void addSearchAudienceScopeHandling(ClassCustomization customization, Logger logger) { | ||
| customization.customizeAst(ast -> ast.getClassByName(customization.getClassName()).ifPresent(clazz -> { | ||
| // Make sure 'DEFAULT_SCOPES' exists before adding instance level 'scopes' | ||
| if (clazz.getMembers().stream().noneMatch(declaration -> declaration.isFieldDeclaration() | ||
| && "DEFAULT_SCOPES".equals(declaration.asFieldDeclaration().getVariable(0).getNameAsString()))) { | ||
| logger.info( | ||
| "Client builder didn't contain field 'DEFAULT_SCOPES', skipping adding support for SearchAudience"); | ||
| return; | ||
| } | ||
|
|
||
| // Add mutable instance 'String[] scopes' with an initialized value of 'DEFAULT_SCOPES'. Also, add the | ||
| // Generated annotation so this will get cleaned up automatically in the future when the TypeSpec issue is | ||
| // resolved. | ||
| clazz.addMember(new FieldDeclaration().setModifiers(Modifier.Keyword.PRIVATE) | ||
| .addMarkerAnnotation("Generated") | ||
| .addVariable(new VariableDeclarator().setName("scopes").setType("String[]") | ||
| .setInitializer("DEFAULT_SCOPES"))); | ||
|
|
||
| // Get the 'createHttpPipeline' method and change the 'BearerTokenAuthenticationPolicy' to use 'scopes' | ||
| // instead of 'DEFAULT_SCOPES' when creating the object. | ||
| clazz.getMethodsByName("createHttpPipeline").forEach(method -> method.getBody().ifPresent(body -> | ||
| method.setBody(StaticJavaParser.parseBlock(body.toString().replace("DEFAULT_SCOPES", "scopes"))))); | ||
|
alzimmermsft marked this conversation as resolved.
|
||
| })); | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.