Skip to content

Commit

Permalink
Merge branch 'main' into fix-parameter-name-issue
Browse files Browse the repository at this point in the history
  • Loading branch information
ArcturusZhang authored Jan 15, 2025
2 parents 29d219d + 72dc2a9 commit 9d9133e
Show file tree
Hide file tree
Showing 81 changed files with 1,502 additions and 258 deletions.
7 changes: 7 additions & 0 deletions .chronus/changes/hide-codegen-config-2025-0-15-9-4-57.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: internal
packages:
- typespec-vscode
---

remove vscode settings for code generation
7 changes: 0 additions & 7 deletions .chronus/changes/http_spec_pageable-2025-0-9-13-43-18.md

This file was deleted.

8 changes: 8 additions & 0 deletions .chronus/changes/scaffolding-emitter-2025-0-14-11-30-33.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
changeKind: feature
packages:
- "@typespec/compiler"
- typespec-vscode
---

Support Emitters section in Init Template when creating TypeSpec project in vscode
7 changes: 0 additions & 7 deletions .chronus/changes/tadelesh-patch-1-2024-11-18-16-37-2.md

This file was deleted.

3 changes: 2 additions & 1 deletion packages/compiler/src/server/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import {
import { TextDocument, TextEdit } from "vscode-languageserver-textdocument";
import type { CompilerHost, Program, SourceFile, TypeSpecScriptNode } from "../core/index.js";
import { LoadedCoreTemplates } from "../init/core-templates.js";
import { InitTemplate, InitTemplateLibrarySpec } from "../init/init-template.js";
import { EmitterTemplate, InitTemplate, InitTemplateLibrarySpec } from "../init/init-template.js";
import { ScaffoldingConfig } from "../init/scaffold.js";

export type ServerLogLevel = "trace" | "debug" | "info" | "warning" | "error";
Expand Down Expand Up @@ -172,3 +172,4 @@ export interface InitProjectContext {
export type InitProjectConfig = ScaffoldingConfig;
export type InitProjectTemplate = InitTemplate;
export type InitProjectTemplateLibrarySpec = InitTemplateLibrarySpec;
export type InitProjectTemplateEmitterTemplate = EmitterTemplate;
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the MIT License.

using System;
using System.ClientModel;
using System.ClientModel.Primitives;
using System.Collections.Generic;
using System.Diagnostics;
Expand All @@ -26,7 +25,7 @@ namespace Microsoft.Generator.CSharp.ClientModel.Providers
/// <summary>
/// This class provides the set of serialization models, methods, and interfaces for a given model.
/// </summary>
internal class MrwSerializationTypeDefinition : TypeProvider
public class MrwSerializationTypeDefinition : TypeProvider
{
private const string JsonModelWriteCoreMethodName = "JsonModelWriteCore";
private const string JsonModelCreateCoreMethodName = "JsonModelCreateCore";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ protected internal TypeFactory()
return modelProvider;
}

private ModelProvider? CreateModelCore(InputModelType model)
protected virtual ModelProvider? CreateModelCore(InputModelType model)
{
ModelProvider? type = new ModelProvider(model);
if (Visitors.Count == 0)
Expand Down
25 changes: 18 additions & 7 deletions packages/http-client-java/emitter/src/code-model-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,13 +322,24 @@ export class CodeModelBuilder {
switch (scheme.type) {
case "oauth2":
{
const oauth2Scheme = new OAuth2SecurityScheme({
scopes: [],
});
scheme.flows.forEach((it) =>
oauth2Scheme.scopes.push(...it.scopes.map((it) => it.value)),
);
securitySchemes.push(oauth2Scheme);
if (this.isBranded()) {
const oauth2Scheme = new OAuth2SecurityScheme({
scopes: [],
});
scheme.flows.forEach((it) =>
oauth2Scheme.scopes.push(...it.scopes.map((it) => it.value)),
);
securitySchemes.push(oauth2Scheme);
} else {
// there is no TokenCredential in clientcore, hence use Bearer Authentication directly
this.logWarning(`OAuth2 auth scheme is generated as KeyCredential.`);

const keyScheme = new KeySecurityScheme({
name: "authorization",
});
(keyScheme as any).prefix = "Bearer";
securitySchemes.push(keyScheme);
}
}
break;

Expand Down
3 changes: 3 additions & 0 deletions packages/http-client-java/eng/scripts/Build-Packages.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ try {
Invoke-LoggedCommand "mvn -version"

Invoke-LoggedCommand "mvn clean install --no-transfer-progress -T 1C -f ./pom.xml"

# check code format
Invoke-LoggedCommand "mvn spotless:check --activate-profiles test"
}
finally {
Pop-Location
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,6 @@ Copy-Item -Path node_modules/@typespec/http-specs/specs -Destination ./ -Recurse
# remove xml tests, emitter has not supported xml model
Remove-Item ./specs/payload/xml -Recurse -Force

# TokenCredential not in core
Remove-Item ./specs/authentication/oauth2 -Recurse -Force
Remove-Item ./specs/authentication/union -Recurse -Force
# Base64Url not in core
Remove-Item ./specs/encode/bytes -Recurse -Force
# DateTimeRfc1123 is private in beta.1, should now be public in main
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ public HttpPipeline getHttpPipeline() {
* @param endpoint Service host.
*/
public ApiKeyClientImpl(HttpPipeline httpPipeline, String endpoint) {
this.endpoint = "http://localhost:3000";
this.httpPipeline = httpPipeline;
this.endpoint = endpoint;
this.service = RestProxy.create(ApiKeyClientService.class, this.httpPipeline);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ public HttpPipeline getHttpPipeline() {
* @param endpoint Service host.
*/
public CustomClientImpl(HttpPipeline httpPipeline, String endpoint) {
this.endpoint = "http://localhost:3000";
this.httpPipeline = httpPipeline;
this.endpoint = endpoint;
this.service = RestProxy.create(CustomClientService.class, this.httpPipeline);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Code generated by Microsoft (R) TypeSpec Code Generator.

package authentication.oauth2;

import io.clientcore.core.annotation.Metadata;
import io.clientcore.core.annotation.TypeConditions;
import io.clientcore.core.serialization.json.JsonReader;
import io.clientcore.core.serialization.json.JsonSerializable;
import io.clientcore.core.serialization.json.JsonToken;
import io.clientcore.core.serialization.json.JsonWriter;
import java.io.IOException;

/**
* The InvalidAuth model.
*/
@Metadata(conditions = { TypeConditions.IMMUTABLE })
public final class InvalidAuth implements JsonSerializable<InvalidAuth> {
/*
* The error property.
*/
@Metadata(generated = true)
private final String error;

/**
* Creates an instance of InvalidAuth class.
*
* @param error the error value to set.
*/
@Metadata(generated = true)
private InvalidAuth(String error) {
this.error = error;
}

/**
* Get the error property: The error property.
*
* @return the error value.
*/
@Metadata(generated = true)
public String getError() {
return this.error;
}

/**
* {@inheritDoc}
*/
@Metadata(generated = true)
@Override
public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
jsonWriter.writeStartObject();
jsonWriter.writeStringField("error", this.error);
return jsonWriter.writeEndObject();
}

/**
* Reads an instance of InvalidAuth from the JsonReader.
*
* @param jsonReader The JsonReader being read.
* @return An instance of InvalidAuth if the JsonReader was pointing to an instance of it, or null if it was
* pointing to JSON null.
* @throws IllegalStateException If the deserialized JSON object was missing any required properties.
* @throws IOException If an error occurs while reading the InvalidAuth.
*/
@Metadata(generated = true)
public static InvalidAuth fromJson(JsonReader jsonReader) throws IOException {
return jsonReader.readObject(reader -> {
String error = null;
while (reader.nextToken() != JsonToken.END_OBJECT) {
String fieldName = reader.getFieldName();
reader.nextToken();

if ("error".equals(fieldName)) {
error = reader.getString();
} else {
reader.skipChildren();
}
}
return new InvalidAuth(error);
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Code generated by Microsoft (R) TypeSpec Code Generator.

package authentication.oauth2;

import authentication.oauth2.implementation.OAuth2ClientImpl;
import io.clientcore.core.annotation.Metadata;
import io.clientcore.core.annotation.ServiceClient;
import io.clientcore.core.http.exception.HttpResponseException;
import io.clientcore.core.http.models.RequestOptions;
import io.clientcore.core.http.models.Response;

/**
* Initializes a new instance of the synchronous OAuth2Client type.
*/
@ServiceClient(builder = OAuth2ClientBuilder.class)
public final class OAuth2Client {
@Metadata(generated = true)
private final OAuth2ClientImpl serviceClient;

/**
* Initializes an instance of OAuth2Client class.
*
* @param serviceClient the service client implementation.
*/
@Metadata(generated = true)
OAuth2Client(OAuth2ClientImpl serviceClient) {
this.serviceClient = serviceClient;
}

/**
* Check whether client is authenticated.
*
* @param requestOptions The options to configure the HTTP request before HTTP client sends it.
* @throws HttpResponseException thrown if the service returns an error.
* @return the response.
*/
@Metadata(generated = true)
public Response<Void> validWithResponse(RequestOptions requestOptions) {
return this.serviceClient.validWithResponse(requestOptions);
}

/**
* Check whether client is authenticated. Will return an invalid bearer error.
*
* @param requestOptions The options to configure the HTTP request before HTTP client sends it.
* @throws HttpResponseException thrown if the service returns an error.
* @return the response.
*/
@Metadata(generated = true)
public Response<Void> invalidWithResponse(RequestOptions requestOptions) {
return this.serviceClient.invalidWithResponse(requestOptions);
}

/**
* Check whether client is authenticated.
*
* @throws HttpResponseException thrown if the service returns an error.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
*/
@Metadata(generated = true)
public void valid() {
// Generated convenience method for validWithResponse
RequestOptions requestOptions = new RequestOptions();
validWithResponse(requestOptions).getValue();
}

/**
* Check whether client is authenticated. Will return an invalid bearer error.
*
* @throws HttpResponseException thrown if the service returns an error.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
*/
@Metadata(generated = true)
public void invalid() {
// Generated convenience method for invalidWithResponse
RequestOptions requestOptions = new RequestOptions();
invalidWithResponse(requestOptions).getValue();
}
}
Loading

0 comments on commit 9d9133e

Please sign in to comment.