diff --git a/packages/typespec-go/.scripts/tspcompile.js b/packages/typespec-go/.scripts/tspcompile.js index e72958bf2..1ffd0d994 100644 --- a/packages/typespec-go/.scripts/tspcompile.js +++ b/packages/typespec-go/.scripts/tspcompile.js @@ -18,6 +18,7 @@ const compiler = pkgRoot + 'node_modules/@typespec/compiler/cmd/tsp.js'; // 'moduleName': [ 'input', 'emitter option 1', 'emitter option N...' ] // if no .tsp file is specified in input, it's assumed to be main.tsp const httpSpecsGroup = { + 'documentationgroup': ['documentation'], 'apikeygroup': ['authentication/api-key'], // ctors for API key not supported 'customgroup': ['authentication/http/custom'], // ctors for API key not supported 'oauth2group': ['authentication/oauth2'], diff --git a/packages/typespec-go/test/http-specs/documentationgroup/LICENSE.txt b/packages/typespec-go/test/http-specs/documentationgroup/LICENSE.txt new file mode 100644 index 000000000..48ea6616b --- /dev/null +++ b/packages/typespec-go/test/http-specs/documentationgroup/LICENSE.txt @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) Microsoft Corporation. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE diff --git a/packages/typespec-go/test/http-specs/documentationgroup/documentationlists_client_test.go b/packages/typespec-go/test/http-specs/documentationgroup/documentationlists_client_test.go new file mode 100644 index 000000000..48975d799 --- /dev/null +++ b/packages/typespec-go/test/http-specs/documentationgroup/documentationlists_client_test.go @@ -0,0 +1,37 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. + +package documentationgroup_test + +import ( + "context" + "documentationgroup" + "testing" + + "github.com/stretchr/testify/require" +) + +func TestListsClient_BulletPointsModel(t *testing.T) { + client, err := documentationgroup.NewDocumentationClientWithNoCredential("http://localhost:3000", nil) + require.NoError(t, err) + enumValue := documentationgroup.BulletPointsEnum("Simple") + resp, err := client.NewDocumentationListsClient().BulletPointsModel(context.Background(), documentationgroup.BulletPointsModel{Prop: &enumValue}, nil) + require.NoError(t, err) + require.Zero(t, resp) +} + +func TestListsClient_Numbered(t *testing.T) { + client, err := documentationgroup.NewDocumentationClientWithNoCredential("http://localhost:3000", nil) + require.NoError(t, err) + resp, err := client.NewDocumentationListsClient().Numbered(context.Background(), nil) + require.NoError(t, err) + require.Zero(t, resp) +} + +func TestListsClient_BulletPointsOp(t *testing.T) { + client, err := documentationgroup.NewDocumentationClientWithNoCredential("http://localhost:3000", nil) + require.NoError(t, err) + resp, err := client.NewDocumentationListsClient().BulletPointsOp(context.Background(), nil) + require.NoError(t, err) + require.Zero(t, resp) +} diff --git a/packages/typespec-go/test/http-specs/documentationgroup/documentationtextformatting_client_test.go b/packages/typespec-go/test/http-specs/documentationgroup/documentationtextformatting_client_test.go new file mode 100644 index 000000000..dd561b860 --- /dev/null +++ b/packages/typespec-go/test/http-specs/documentationgroup/documentationtextformatting_client_test.go @@ -0,0 +1,36 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. + +package documentationgroup_test + +import ( + "context" + "documentationgroup" + "testing" + + "github.com/stretchr/testify/require" +) + +func TestTextFormattingClient_BoldText(t *testing.T) { + client, err := documentationgroup.NewDocumentationClientWithNoCredential("http://localhost:3000", nil) + require.NoError(t, err) + resp, err := client.NewDocumentationTextFormattingClient().BoldText(context.Background(), nil) + require.NoError(t, err) + require.Zero(t, resp) +} + +func TestTextFormattingClient_CombinedFormatting(t *testing.T) { + client, err := documentationgroup.NewDocumentationClientWithNoCredential("http://localhost:3000", nil) + require.NoError(t, err) + resp, err := client.NewDocumentationTextFormattingClient().CombinedFormatting(context.Background(), nil) + require.NoError(t, err) + require.Zero(t, resp) +} + +func TestTextFormattingClient_ItalicText(t *testing.T) { + client, err := documentationgroup.NewDocumentationClientWithNoCredential("http://localhost:3000", nil) + require.NoError(t, err) + resp, err := client.NewDocumentationTextFormattingClient().ItalicText(context.Background(), nil) + require.NoError(t, err) + require.Zero(t, resp) +} diff --git a/packages/typespec-go/test/http-specs/documentationgroup/fake/zz_documentation_server.go b/packages/typespec-go/test/http-specs/documentationgroup/fake/zz_documentation_server.go new file mode 100644 index 000000000..f2841ecbc --- /dev/null +++ b/packages/typespec-go/test/http-specs/documentationgroup/fake/zz_documentation_server.go @@ -0,0 +1,78 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) Go Code Generator. DO NOT EDIT. + +package fake + +import ( + "errors" + "fmt" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "net/http" + "strings" + "sync" +) + +// DocumentationServer is a fake server for instances of the documentationgroup.DocumentationClient type. +type DocumentationServer struct { + // DocumentationListsServer contains the fakes for client DocumentationListsClient + DocumentationListsServer DocumentationListsServer + + // DocumentationTextFormattingServer contains the fakes for client DocumentationTextFormattingClient + DocumentationTextFormattingServer DocumentationTextFormattingServer +} + +// NewDocumentationServerTransport creates a new instance of DocumentationServerTransport with the provided implementation. +// The returned DocumentationServerTransport instance is connected to an instance of documentationgroup.DocumentationClient via the +// azcore.ClientOptions.Transporter field in the client's constructor parameters. +func NewDocumentationServerTransport(srv *DocumentationServer) *DocumentationServerTransport { + return &DocumentationServerTransport{srv: srv} +} + +// DocumentationServerTransport connects instances of documentationgroup.DocumentationClient to instances of DocumentationServer. +// Don't use this type directly, use NewDocumentationServerTransport instead. +type DocumentationServerTransport struct { + srv *DocumentationServer + trMu sync.Mutex + trDocumentationListsServer *DocumentationListsServerTransport + trDocumentationTextFormattingServer *DocumentationTextFormattingServerTransport +} + +// Do implements the policy.Transporter interface for DocumentationServerTransport. +func (d *DocumentationServerTransport) Do(req *http.Request) (*http.Response, error) { + rawMethod := req.Context().Value(runtime.CtxAPINameKey{}) + method, ok := rawMethod.(string) + if !ok { + return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")} + } + + return d.dispatchToClientFake(req, method[:strings.Index(method, ".")]) +} + +func (d *DocumentationServerTransport) dispatchToClientFake(req *http.Request, client string) (*http.Response, error) { + var resp *http.Response + var err error + + switch client { + case "DocumentationListsClient": + initServer(&d.trMu, &d.trDocumentationListsServer, func() *DocumentationListsServerTransport { + return NewDocumentationListsServerTransport(&d.srv.DocumentationListsServer) + }) + resp, err = d.trDocumentationListsServer.Do(req) + case "DocumentationTextFormattingClient": + initServer(&d.trMu, &d.trDocumentationTextFormattingServer, func() *DocumentationTextFormattingServerTransport { + return NewDocumentationTextFormattingServerTransport(&d.srv.DocumentationTextFormattingServer) + }) + resp, err = d.trDocumentationTextFormattingServer.Do(req) + default: + err = fmt.Errorf("unhandled client %s", client) + } + + return resp, err +} + +// set this to conditionally intercept incoming requests to DocumentationServerTransport +var documentationServerTransportInterceptor interface { + // Do returns true if the server transport should use the returned response/error + Do(*http.Request) (*http.Response, error, bool) +} diff --git a/packages/typespec-go/test/http-specs/documentationgroup/fake/zz_documentationlists_server.go b/packages/typespec-go/test/http-specs/documentationgroup/fake/zz_documentationlists_server.go new file mode 100644 index 000000000..b917a4c79 --- /dev/null +++ b/packages/typespec-go/test/http-specs/documentationgroup/fake/zz_documentationlists_server.go @@ -0,0 +1,162 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) Go Code Generator. DO NOT EDIT. + +package fake + +import ( + "context" + "documentationgroup" + "errors" + "fmt" + azfake "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "net/http" +) + +// DocumentationListsServer is a fake server for instances of the documentationgroup.DocumentationListsClient type. +type DocumentationListsServer struct { + // BulletPointsModel is the fake for method DocumentationListsClient.BulletPointsModel + // HTTP status codes to indicate success: http.StatusOK + BulletPointsModel func(ctx context.Context, input documentationgroup.BulletPointsModel, options *documentationgroup.DocumentationListsClientBulletPointsModelOptions) (resp azfake.Responder[documentationgroup.DocumentationListsClientBulletPointsModelResponse], errResp azfake.ErrorResponder) + + // BulletPointsOp is the fake for method DocumentationListsClient.BulletPointsOp + // HTTP status codes to indicate success: http.StatusNoContent + BulletPointsOp func(ctx context.Context, options *documentationgroup.DocumentationListsClientBulletPointsOpOptions) (resp azfake.Responder[documentationgroup.DocumentationListsClientBulletPointsOpResponse], errResp azfake.ErrorResponder) + + // Numbered is the fake for method DocumentationListsClient.Numbered + // HTTP status codes to indicate success: http.StatusNoContent + Numbered func(ctx context.Context, options *documentationgroup.DocumentationListsClientNumberedOptions) (resp azfake.Responder[documentationgroup.DocumentationListsClientNumberedResponse], errResp azfake.ErrorResponder) +} + +// NewDocumentationListsServerTransport creates a new instance of DocumentationListsServerTransport with the provided implementation. +// The returned DocumentationListsServerTransport instance is connected to an instance of documentationgroup.DocumentationListsClient via the +// azcore.ClientOptions.Transporter field in the client's constructor parameters. +func NewDocumentationListsServerTransport(srv *DocumentationListsServer) *DocumentationListsServerTransport { + return &DocumentationListsServerTransport{srv: srv} +} + +// DocumentationListsServerTransport connects instances of documentationgroup.DocumentationListsClient to instances of DocumentationListsServer. +// Don't use this type directly, use NewDocumentationListsServerTransport instead. +type DocumentationListsServerTransport struct { + srv *DocumentationListsServer +} + +// Do implements the policy.Transporter interface for DocumentationListsServerTransport. +func (d *DocumentationListsServerTransport) Do(req *http.Request) (*http.Response, error) { + rawMethod := req.Context().Value(runtime.CtxAPINameKey{}) + method, ok := rawMethod.(string) + if !ok { + return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")} + } + + return d.dispatchToMethodFake(req, method) +} + +func (d *DocumentationListsServerTransport) dispatchToMethodFake(req *http.Request, method string) (*http.Response, error) { + resultChan := make(chan result) + defer close(resultChan) + + go func() { + var intercepted bool + var res result + if documentationListsServerTransportInterceptor != nil { + res.resp, res.err, intercepted = documentationListsServerTransportInterceptor.Do(req) + } + if !intercepted { + switch method { + case "DocumentationListsClient.BulletPointsModel": + res.resp, res.err = d.dispatchBulletPointsModel(req) + case "DocumentationListsClient.BulletPointsOp": + res.resp, res.err = d.dispatchBulletPointsOp(req) + case "DocumentationListsClient.Numbered": + res.resp, res.err = d.dispatchNumbered(req) + default: + res.err = fmt.Errorf("unhandled API %s", method) + } + + } + select { + case resultChan <- res: + case <-req.Context().Done(): + } + }() + + select { + case <-req.Context().Done(): + return nil, req.Context().Err() + case res := <-resultChan: + return res.resp, res.err + } +} + +func (d *DocumentationListsServerTransport) dispatchBulletPointsModel(req *http.Request) (*http.Response, error) { + if d.srv.BulletPointsModel == nil { + return nil, &nonRetriableError{errors.New("fake for method BulletPointsModel not implemented")} + } + type partialBodyParams struct { + Input documentationgroup.BulletPointsModel `json:"input"` + } + body, err := server.UnmarshalRequestAsJSON[partialBodyParams](req) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.BulletPointsModel(req.Context(), body.Input, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)} + } + resp, err := server.NewResponse(respContent, req, nil) + if err != nil { + return nil, err + } + return resp, nil +} + +func (d *DocumentationListsServerTransport) dispatchBulletPointsOp(req *http.Request) (*http.Response, error) { + if d.srv.BulletPointsOp == nil { + return nil, &nonRetriableError{errors.New("fake for method BulletPointsOp not implemented")} + } + respr, errRespr := d.srv.BulletPointsOp(req.Context(), nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusNoContent}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusNoContent", respContent.HTTPStatus)} + } + resp, err := server.NewResponse(respContent, req, nil) + if err != nil { + return nil, err + } + return resp, nil +} + +func (d *DocumentationListsServerTransport) dispatchNumbered(req *http.Request) (*http.Response, error) { + if d.srv.Numbered == nil { + return nil, &nonRetriableError{errors.New("fake for method Numbered not implemented")} + } + respr, errRespr := d.srv.Numbered(req.Context(), nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusNoContent}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusNoContent", respContent.HTTPStatus)} + } + resp, err := server.NewResponse(respContent, req, nil) + if err != nil { + return nil, err + } + return resp, nil +} + +// set this to conditionally intercept incoming requests to DocumentationListsServerTransport +var documentationListsServerTransportInterceptor interface { + // Do returns true if the server transport should use the returned response/error + Do(*http.Request) (*http.Response, error, bool) +} diff --git a/packages/typespec-go/test/http-specs/documentationgroup/fake/zz_documentationtextformatting_server.go b/packages/typespec-go/test/http-specs/documentationgroup/fake/zz_documentationtextformatting_server.go new file mode 100644 index 000000000..edce77ee1 --- /dev/null +++ b/packages/typespec-go/test/http-specs/documentationgroup/fake/zz_documentationtextformatting_server.go @@ -0,0 +1,155 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) Go Code Generator. DO NOT EDIT. + +package fake + +import ( + "context" + "documentationgroup" + "errors" + "fmt" + azfake "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "net/http" +) + +// DocumentationTextFormattingServer is a fake server for instances of the documentationgroup.DocumentationTextFormattingClient type. +type DocumentationTextFormattingServer struct { + // BoldText is the fake for method DocumentationTextFormattingClient.BoldText + // HTTP status codes to indicate success: http.StatusNoContent + BoldText func(ctx context.Context, options *documentationgroup.DocumentationTextFormattingClientBoldTextOptions) (resp azfake.Responder[documentationgroup.DocumentationTextFormattingClientBoldTextResponse], errResp azfake.ErrorResponder) + + // CombinedFormatting is the fake for method DocumentationTextFormattingClient.CombinedFormatting + // HTTP status codes to indicate success: http.StatusNoContent + CombinedFormatting func(ctx context.Context, options *documentationgroup.DocumentationTextFormattingClientCombinedFormattingOptions) (resp azfake.Responder[documentationgroup.DocumentationTextFormattingClientCombinedFormattingResponse], errResp azfake.ErrorResponder) + + // ItalicText is the fake for method DocumentationTextFormattingClient.ItalicText + // HTTP status codes to indicate success: http.StatusNoContent + ItalicText func(ctx context.Context, options *documentationgroup.DocumentationTextFormattingClientItalicTextOptions) (resp azfake.Responder[documentationgroup.DocumentationTextFormattingClientItalicTextResponse], errResp azfake.ErrorResponder) +} + +// NewDocumentationTextFormattingServerTransport creates a new instance of DocumentationTextFormattingServerTransport with the provided implementation. +// The returned DocumentationTextFormattingServerTransport instance is connected to an instance of documentationgroup.DocumentationTextFormattingClient via the +// azcore.ClientOptions.Transporter field in the client's constructor parameters. +func NewDocumentationTextFormattingServerTransport(srv *DocumentationTextFormattingServer) *DocumentationTextFormattingServerTransport { + return &DocumentationTextFormattingServerTransport{srv: srv} +} + +// DocumentationTextFormattingServerTransport connects instances of documentationgroup.DocumentationTextFormattingClient to instances of DocumentationTextFormattingServer. +// Don't use this type directly, use NewDocumentationTextFormattingServerTransport instead. +type DocumentationTextFormattingServerTransport struct { + srv *DocumentationTextFormattingServer +} + +// Do implements the policy.Transporter interface for DocumentationTextFormattingServerTransport. +func (d *DocumentationTextFormattingServerTransport) Do(req *http.Request) (*http.Response, error) { + rawMethod := req.Context().Value(runtime.CtxAPINameKey{}) + method, ok := rawMethod.(string) + if !ok { + return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")} + } + + return d.dispatchToMethodFake(req, method) +} + +func (d *DocumentationTextFormattingServerTransport) dispatchToMethodFake(req *http.Request, method string) (*http.Response, error) { + resultChan := make(chan result) + defer close(resultChan) + + go func() { + var intercepted bool + var res result + if documentationTextFormattingServerTransportInterceptor != nil { + res.resp, res.err, intercepted = documentationTextFormattingServerTransportInterceptor.Do(req) + } + if !intercepted { + switch method { + case "DocumentationTextFormattingClient.BoldText": + res.resp, res.err = d.dispatchBoldText(req) + case "DocumentationTextFormattingClient.CombinedFormatting": + res.resp, res.err = d.dispatchCombinedFormatting(req) + case "DocumentationTextFormattingClient.ItalicText": + res.resp, res.err = d.dispatchItalicText(req) + default: + res.err = fmt.Errorf("unhandled API %s", method) + } + + } + select { + case resultChan <- res: + case <-req.Context().Done(): + } + }() + + select { + case <-req.Context().Done(): + return nil, req.Context().Err() + case res := <-resultChan: + return res.resp, res.err + } +} + +func (d *DocumentationTextFormattingServerTransport) dispatchBoldText(req *http.Request) (*http.Response, error) { + if d.srv.BoldText == nil { + return nil, &nonRetriableError{errors.New("fake for method BoldText not implemented")} + } + respr, errRespr := d.srv.BoldText(req.Context(), nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusNoContent}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusNoContent", respContent.HTTPStatus)} + } + resp, err := server.NewResponse(respContent, req, nil) + if err != nil { + return nil, err + } + return resp, nil +} + +func (d *DocumentationTextFormattingServerTransport) dispatchCombinedFormatting(req *http.Request) (*http.Response, error) { + if d.srv.CombinedFormatting == nil { + return nil, &nonRetriableError{errors.New("fake for method CombinedFormatting not implemented")} + } + respr, errRespr := d.srv.CombinedFormatting(req.Context(), nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusNoContent}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusNoContent", respContent.HTTPStatus)} + } + resp, err := server.NewResponse(respContent, req, nil) + if err != nil { + return nil, err + } + return resp, nil +} + +func (d *DocumentationTextFormattingServerTransport) dispatchItalicText(req *http.Request) (*http.Response, error) { + if d.srv.ItalicText == nil { + return nil, &nonRetriableError{errors.New("fake for method ItalicText not implemented")} + } + respr, errRespr := d.srv.ItalicText(req.Context(), nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusNoContent}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusNoContent", respContent.HTTPStatus)} + } + resp, err := server.NewResponse(respContent, req, nil) + if err != nil { + return nil, err + } + return resp, nil +} + +// set this to conditionally intercept incoming requests to DocumentationTextFormattingServerTransport +var documentationTextFormattingServerTransportInterceptor interface { + // Do returns true if the server transport should use the returned response/error + Do(*http.Request) (*http.Response, error, bool) +} diff --git a/packages/typespec-go/test/http-specs/documentationgroup/fake/zz_internal.go b/packages/typespec-go/test/http-specs/documentationgroup/fake/zz_internal.go new file mode 100644 index 000000000..edd9ca564 --- /dev/null +++ b/packages/typespec-go/test/http-specs/documentationgroup/fake/zz_internal.go @@ -0,0 +1,40 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) Go Code Generator. DO NOT EDIT. + +package fake + +import ( + "net/http" + "sync" +) + +type result struct { + resp *http.Response + err error +} + +type nonRetriableError struct { + error +} + +func (nonRetriableError) NonRetriable() { + // marker method +} + +func contains[T comparable](s []T, v T) bool { + for _, vv := range s { + if vv == v { + return true + } + } + return false +} + +func initServer[T any](mu *sync.Mutex, dst **T, src func() *T) { + mu.Lock() + if *dst == nil { + *dst = src() + } + mu.Unlock() +} diff --git a/packages/typespec-go/test/http-specs/documentationgroup/go.mod b/packages/typespec-go/test/http-specs/documentationgroup/go.mod new file mode 100644 index 000000000..216bc4f32 --- /dev/null +++ b/packages/typespec-go/test/http-specs/documentationgroup/go.mod @@ -0,0 +1,17 @@ +module documentationgroup + +go 1.24.0 + +require ( + github.com/Azure/azure-sdk-for-go/sdk/azcore v1.21.0 + github.com/stretchr/testify v1.11.1 +) + +require ( + github.com/Azure/azure-sdk-for-go/sdk/internal v1.11.2 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + golang.org/x/net v0.49.0 // indirect + golang.org/x/text v0.33.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect +) diff --git a/packages/typespec-go/test/http-specs/documentationgroup/go.sum b/packages/typespec-go/test/http-specs/documentationgroup/go.sum new file mode 100644 index 000000000..104d7f822 --- /dev/null +++ b/packages/typespec-go/test/http-specs/documentationgroup/go.sum @@ -0,0 +1,25 @@ +github.com/Azure/azure-sdk-for-go/sdk/azcore v1.21.0 h1:fou+2+WFTib47nS+nz/ozhEBnvU96bKHy6LjRsY4E28= +github.com/Azure/azure-sdk-for-go/sdk/azcore v1.21.0/go.mod h1:t76Ruy8AHvUAC8GfMWJMa0ElSbuIcO03NLpynfbgsPA= +github.com/Azure/azure-sdk-for-go/sdk/internal v1.11.2 h1:9iefClla7iYpfYWdzPCRDozdmndjTm8DXdpCzPajMgA= +github.com/Azure/azure-sdk-for-go/sdk/internal v1.11.2/go.mod h1:XtLgD3ZD34DAaVIIAyG3objl5DynM3CQ/vMcbBNJZGI= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= +github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4= +github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= +github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= +golang.org/x/net v0.49.0 h1:eeHFmOGUTtaaPSGNmjBKpbng9MulQsJURQUAfUwY++o= +golang.org/x/net v0.49.0/go.mod h1:/ysNB2EvaqvesRkuLAyjI1ycPZlQHM3q01F02UY/MV8= +golang.org/x/text v0.33.0 h1:B3njUFyqtHDUI5jMn1YIr5B0IE2U0qck04r6d4KPAxE= +golang.org/x/text v0.33.0/go.mod h1:LuMebE6+rBincTi9+xWTY8TztLzKHc/9C1uBCG27+q8= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/packages/typespec-go/test/http-specs/documentationgroup/testdata/_metadata.json b/packages/typespec-go/test/http-specs/documentationgroup/testdata/_metadata.json new file mode 100644 index 000000000..fe1d7908e --- /dev/null +++ b/packages/typespec-go/test/http-specs/documentationgroup/testdata/_metadata.json @@ -0,0 +1,3 @@ +{ + "emitterVersion": "0.0.0" +} diff --git a/packages/typespec-go/test/http-specs/documentationgroup/zz_constants.go b/packages/typespec-go/test/http-specs/documentationgroup/zz_constants.go new file mode 100644 index 000000000..d1b19de04 --- /dev/null +++ b/packages/typespec-go/test/http-specs/documentationgroup/zz_constants.go @@ -0,0 +1,54 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) Go Code Generator. DO NOT EDIT. + +package documentationgroup + +// BulletPointsEnum - This tests really long bullet points in enum documentation to see how wrapping and formatting are handled. +// This should wrap around correctly and maintain proper indentation for each line. +// - Simple bullet point. This bullet point is going to be very long to test how text wrapping is handled in bullet points +// within documentation comments. It should properly indent the wrapped lines. +// - Another bullet point with **bold text**. This bullet point is also intentionally long to see how the formatting is preserved +// when the text wraps onto multiple lines in the generated documentation. +// - Third bullet point with *italic text*. Similar to the previous points, this one is extended to ensure that the wrapping +// and formatting are correctly applied in the output. +// - Complex bullet point with **bold** and *italic* combined. This bullet point combines both bold and italic formatting +// and is long enough to test the wrapping behavior in such cases. +// - **Bold bullet point**: A bullet point that is entirely bolded. This point is also made lengthy to observe how the bold +// formatting is maintained across wrapped lines. +// - *Italic bullet point*: A bullet point that is entirely italicized. This final point is extended to verify that italic +// formatting is correctly applied even when the text spans multiple lines. +type BulletPointsEnum string + +const ( + // BulletPointsEnumBold - Bullet point with **bold text**. This line is intentionally long to test text wrapping in bullet + // points within enum documentation comments. It should properly indent the wrapped lines. + // - **One**: one. This line is intentionally long to test text wrapping in bullet points within enum documentation comments. + // It should properly indent the wrapped lines. + // - **Two**: two. This line is intentionally long to test text wrapping in bullet points within enum documentation comments. + // It should properly indent the wrapped lines. + BulletPointsEnumBold BulletPointsEnum = "Bold" + // BulletPointsEnumItalic - Bullet point with *italic text*. This line is intentionally long to test text wrapping in bullet + // points within enum documentation comments. It should properly indent the wrapped lines. + // - *One*: one. This line is intentionally long to test text wrapping in bullet points within enum documentation comments. + // It should properly indent the wrapped lines. + // - *Two*: two. This line is intentionally long to test text wrapping in bullet points within enum documentation comments. + // It should properly indent the wrapped lines. + BulletPointsEnumItalic BulletPointsEnum = "Italic" + // BulletPointsEnumSimple - Simple bullet point. This line is intentionally long to test text wrapping in bullet points within + // enum documentation comments. It should properly indent the wrapped lines. + // - One: one. This line is intentionally long to test text wrapping in bullet points within enum documentation comments. + // It should properly indent the wrapped lines. + // - Two: two. This line is intentionally long to test text wrapping in bullet points within enum documentation comments. + // It should properly indent the wrapped lines. + BulletPointsEnumSimple BulletPointsEnum = "Simple" +) + +// PossibleBulletPointsEnumValues returns the possible values for the BulletPointsEnum const type. +func PossibleBulletPointsEnumValues() []BulletPointsEnum { + return []BulletPointsEnum{ + BulletPointsEnumBold, + BulletPointsEnumItalic, + BulletPointsEnumSimple, + } +} diff --git a/packages/typespec-go/test/http-specs/documentationgroup/zz_documentation_client.go b/packages/typespec-go/test/http-specs/documentationgroup/zz_documentation_client.go new file mode 100644 index 000000000..4f158b1fe --- /dev/null +++ b/packages/typespec-go/test/http-specs/documentationgroup/zz_documentation_client.go @@ -0,0 +1,56 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) Go Code Generator. DO NOT EDIT. + +package documentationgroup + +import ( + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" +) + +// DocumentationClient - Illustrates documentation generation and formatting features +// Don't use this type directly, use NewDocumentationClientWithNoCredential() instead. +type DocumentationClient struct { + internal *azcore.Client + endpoint string +} + +// DocumentationClientOptions contains the optional values for creating a [DocumentationClient]. +type DocumentationClientOptions struct { + azcore.ClientOptions +} + +// NewDocumentationClientWithNoCredential creates a new instance of DocumentationClient with the specified values. +// - endpoint - Service host +// - options - Contains optional client configuration. Pass nil to accept the default values. +func NewDocumentationClientWithNoCredential(endpoint string, options *DocumentationClientOptions) (*DocumentationClient, error) { + if options == nil { + options = &DocumentationClientOptions{} + } + cl, err := azcore.NewClient(moduleName, moduleVersion, runtime.PipelineOptions{}, &options.ClientOptions) + if err != nil { + return nil, err + } + client := &DocumentationClient{ + endpoint: endpoint, + internal: cl, + } + return client, nil +} + +// NewDocumentationListsClient creates a new instance of [DocumentationListsClient]. +func (client *DocumentationClient) NewDocumentationListsClient() *DocumentationListsClient { + return &DocumentationListsClient{ + endpoint: client.endpoint, + internal: client.internal, + } +} + +// NewDocumentationTextFormattingClient creates a new instance of [DocumentationTextFormattingClient]. +func (client *DocumentationClient) NewDocumentationTextFormattingClient() *DocumentationTextFormattingClient { + return &DocumentationTextFormattingClient{ + endpoint: client.endpoint, + internal: client.internal, + } +} diff --git a/packages/typespec-go/test/http-specs/documentationgroup/zz_documentationlists_client.go b/packages/typespec-go/test/http-specs/documentationgroup/zz_documentationlists_client.go new file mode 100644 index 000000000..9bd25c76b --- /dev/null +++ b/packages/typespec-go/test/http-specs/documentationgroup/zz_documentationlists_client.go @@ -0,0 +1,150 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) Go Code Generator. DO NOT EDIT. + +package documentationgroup + +import ( + "context" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "net/http" +) + +// DocumentationListsClient contains the methods for the DocumentationLists group. +// Don't use this type directly, use [DocumentationClient.NewDocumentationListsClient] instead. +type DocumentationListsClient struct { + internal *azcore.Client + endpoint string +} + +// BulletPointsModel - +// If the operation fails it returns an *azcore.ResponseError type. +// - options - DocumentationListsClientBulletPointsModelOptions contains the optional parameters for the DocumentationListsClient.BulletPointsModel +// method. +func (client *DocumentationListsClient) BulletPointsModel(ctx context.Context, input BulletPointsModel, options *DocumentationListsClientBulletPointsModelOptions) (DocumentationListsClientBulletPointsModelResponse, error) { + var err error + const operationName = "DocumentationListsClient.BulletPointsModel" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() + req, err := client.bulletPointsModelCreateRequest(ctx, input, options) + if err != nil { + return DocumentationListsClientBulletPointsModelResponse{}, err + } + httpResp, err := client.internal.Pipeline().Do(req) + if err != nil { + return DocumentationListsClientBulletPointsModelResponse{}, err + } + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return DocumentationListsClientBulletPointsModelResponse{}, err + } + return DocumentationListsClientBulletPointsModelResponse{}, nil +} + +// bulletPointsModelCreateRequest creates the BulletPointsModel request. +func (client *DocumentationListsClient) bulletPointsModelCreateRequest(ctx context.Context, input BulletPointsModel, _ *DocumentationListsClientBulletPointsModelOptions) (*policy.Request, error) { + urlPath := "/documentation/lists/bullet-points/model" + req, err := runtime.NewRequest(ctx, http.MethodPost, runtime.JoinPaths(client.endpoint, urlPath)) + if err != nil { + return nil, err + } + body := struct { + Input BulletPointsModel `json:"input"` + }{ + Input: input, + } + req.Raw().Header["Content-Type"] = []string{"application/json"} + if err := runtime.MarshalAsJSON(req, body); err != nil { + return nil, err + } + return req, nil +} + +// BulletPointsOp - This tests: +// - Simple bullet point. This bullet point is going to be very long to test how text wrapping is handled in bullet points +// within documentation comments. It should properly indent the wrapped lines. +// - Another bullet point with **bold text**. This bullet point is also intentionally long to see how the formatting is preserved +// when the text wraps onto multiple lines in the generated documentation. +// - Third bullet point with *italic text*. Similar to the previous points, this one is extended to ensure that the wrapping +// and formatting are correctly applied in the output. +// - Complex bullet point with **bold** and *italic* combined. This bullet point combines both bold and italic formatting +// and is long enough to test the wrapping behavior in such cases. +// - **Bold bullet point**: A bullet point that is entirely bolded. This point is also made lengthy to observe how the bold +// formatting is maintained across wrapped lines. +// - *Italic bullet point*: A bullet point that is entirely italicized. This final point is extended to verify that italic +// formatting is correctly applied even when the text spans multiple lines. +// If the operation fails it returns an *azcore.ResponseError type. +// - options - DocumentationListsClientBulletPointsOpOptions contains the optional parameters for the DocumentationListsClient.BulletPointsOp +// method. +func (client *DocumentationListsClient) BulletPointsOp(ctx context.Context, options *DocumentationListsClientBulletPointsOpOptions) (DocumentationListsClientBulletPointsOpResponse, error) { + var err error + const operationName = "DocumentationListsClient.BulletPointsOp" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() + req, err := client.bulletPointsOpCreateRequest(ctx, options) + if err != nil { + return DocumentationListsClientBulletPointsOpResponse{}, err + } + httpResp, err := client.internal.Pipeline().Do(req) + if err != nil { + return DocumentationListsClientBulletPointsOpResponse{}, err + } + if !runtime.HasStatusCode(httpResp, http.StatusNoContent) { + err = runtime.NewResponseError(httpResp) + return DocumentationListsClientBulletPointsOpResponse{}, err + } + return DocumentationListsClientBulletPointsOpResponse{}, nil +} + +// bulletPointsOpCreateRequest creates the BulletPointsOp request. +func (client *DocumentationListsClient) bulletPointsOpCreateRequest(ctx context.Context, _ *DocumentationListsClientBulletPointsOpOptions) (*policy.Request, error) { + urlPath := "/documentation/lists/bullet-points/op" + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.endpoint, urlPath)) + if err != nil { + return nil, err + } + return req, nil +} + +// Numbered - Steps to follow: +// 1. First step with **important** note +// 2. Second step with *emphasis* +// 3. Third step combining **bold** and *italic* +// 4. **Final step**: Review all steps for *accuracy*. +// If the operation fails it returns an *azcore.ResponseError type. +// - options - DocumentationListsClientNumberedOptions contains the optional parameters for the DocumentationListsClient.Numbered +// method. +func (client *DocumentationListsClient) Numbered(ctx context.Context, options *DocumentationListsClientNumberedOptions) (DocumentationListsClientNumberedResponse, error) { + var err error + const operationName = "DocumentationListsClient.Numbered" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() + req, err := client.numberedCreateRequest(ctx, options) + if err != nil { + return DocumentationListsClientNumberedResponse{}, err + } + httpResp, err := client.internal.Pipeline().Do(req) + if err != nil { + return DocumentationListsClientNumberedResponse{}, err + } + if !runtime.HasStatusCode(httpResp, http.StatusNoContent) { + err = runtime.NewResponseError(httpResp) + return DocumentationListsClientNumberedResponse{}, err + } + return DocumentationListsClientNumberedResponse{}, nil +} + +// numberedCreateRequest creates the Numbered request. +func (client *DocumentationListsClient) numberedCreateRequest(ctx context.Context, _ *DocumentationListsClientNumberedOptions) (*policy.Request, error) { + urlPath := "/documentation/lists/numbered" + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.endpoint, urlPath)) + if err != nil { + return nil, err + } + return req, nil +} diff --git a/packages/typespec-go/test/http-specs/documentationgroup/zz_documentationtextformatting_client.go b/packages/typespec-go/test/http-specs/documentationgroup/zz_documentationtextformatting_client.go new file mode 100644 index 000000000..b612a6738 --- /dev/null +++ b/packages/typespec-go/test/http-specs/documentationgroup/zz_documentationtextformatting_client.go @@ -0,0 +1,132 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) Go Code Generator. DO NOT EDIT. + +package documentationgroup + +import ( + "context" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "net/http" +) + +// DocumentationTextFormattingClient contains the methods for the DocumentationTextFormatting group. +// Don't use this type directly, use [DocumentationClient.NewDocumentationTextFormattingClient] instead. +type DocumentationTextFormattingClient struct { + internal *azcore.Client + endpoint string +} + +// BoldText - This is **bold text** in the middle of a sentence. +// This is a sentence with **multiple bold** sections and **another bold** section. +// **This entire sentence is bold.** +// If the operation fails it returns an *azcore.ResponseError type. +// - options - DocumentationTextFormattingClientBoldTextOptions contains the optional parameters for the DocumentationTextFormattingClient.BoldText +// method. +func (client *DocumentationTextFormattingClient) BoldText(ctx context.Context, options *DocumentationTextFormattingClientBoldTextOptions) (DocumentationTextFormattingClientBoldTextResponse, error) { + var err error + const operationName = "DocumentationTextFormattingClient.BoldText" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() + req, err := client.boldTextCreateRequest(ctx, options) + if err != nil { + return DocumentationTextFormattingClientBoldTextResponse{}, err + } + httpResp, err := client.internal.Pipeline().Do(req) + if err != nil { + return DocumentationTextFormattingClientBoldTextResponse{}, err + } + if !runtime.HasStatusCode(httpResp, http.StatusNoContent) { + err = runtime.NewResponseError(httpResp) + return DocumentationTextFormattingClientBoldTextResponse{}, err + } + return DocumentationTextFormattingClientBoldTextResponse{}, nil +} + +// boldTextCreateRequest creates the BoldText request. +func (client *DocumentationTextFormattingClient) boldTextCreateRequest(ctx context.Context, _ *DocumentationTextFormattingClientBoldTextOptions) (*policy.Request, error) { + urlPath := "/documentation/text-formatting/bold" + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.endpoint, urlPath)) + if err != nil { + return nil, err + } + return req, nil +} + +// CombinedFormatting - This sentence has **bold**, *italic*, and ***bold italic*** text. +// You can also combine them like **bold with *italic inside* bold**. +// Or *italic with **bold inside** italic*. +// This is a sentence with **bold**, *italic*, and ***bold italic*** text. +// If the operation fails it returns an *azcore.ResponseError type. +// - options - DocumentationTextFormattingClientCombinedFormattingOptions contains the optional parameters for the DocumentationTextFormattingClient.CombinedFormatting +// method. +func (client *DocumentationTextFormattingClient) CombinedFormatting(ctx context.Context, options *DocumentationTextFormattingClientCombinedFormattingOptions) (DocumentationTextFormattingClientCombinedFormattingResponse, error) { + var err error + const operationName = "DocumentationTextFormattingClient.CombinedFormatting" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() + req, err := client.combinedFormattingCreateRequest(ctx, options) + if err != nil { + return DocumentationTextFormattingClientCombinedFormattingResponse{}, err + } + httpResp, err := client.internal.Pipeline().Do(req) + if err != nil { + return DocumentationTextFormattingClientCombinedFormattingResponse{}, err + } + if !runtime.HasStatusCode(httpResp, http.StatusNoContent) { + err = runtime.NewResponseError(httpResp) + return DocumentationTextFormattingClientCombinedFormattingResponse{}, err + } + return DocumentationTextFormattingClientCombinedFormattingResponse{}, nil +} + +// combinedFormattingCreateRequest creates the CombinedFormatting request. +func (client *DocumentationTextFormattingClient) combinedFormattingCreateRequest(ctx context.Context, _ *DocumentationTextFormattingClientCombinedFormattingOptions) (*policy.Request, error) { + urlPath := "/documentation/text-formatting/combined" + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.endpoint, urlPath)) + if err != nil { + return nil, err + } + return req, nil +} + +// ItalicText - This is *italic text* in the middle of a sentence. +// This is a sentence with *multiple italic* sections and *another italic* section. +// *This entire sentence is italic.* +// If the operation fails it returns an *azcore.ResponseError type. +// - options - DocumentationTextFormattingClientItalicTextOptions contains the optional parameters for the DocumentationTextFormattingClient.ItalicText +// method. +func (client *DocumentationTextFormattingClient) ItalicText(ctx context.Context, options *DocumentationTextFormattingClientItalicTextOptions) (DocumentationTextFormattingClientItalicTextResponse, error) { + var err error + const operationName = "DocumentationTextFormattingClient.ItalicText" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() + req, err := client.italicTextCreateRequest(ctx, options) + if err != nil { + return DocumentationTextFormattingClientItalicTextResponse{}, err + } + httpResp, err := client.internal.Pipeline().Do(req) + if err != nil { + return DocumentationTextFormattingClientItalicTextResponse{}, err + } + if !runtime.HasStatusCode(httpResp, http.StatusNoContent) { + err = runtime.NewResponseError(httpResp) + return DocumentationTextFormattingClientItalicTextResponse{}, err + } + return DocumentationTextFormattingClientItalicTextResponse{}, nil +} + +// italicTextCreateRequest creates the ItalicText request. +func (client *DocumentationTextFormattingClient) italicTextCreateRequest(ctx context.Context, _ *DocumentationTextFormattingClientItalicTextOptions) (*policy.Request, error) { + urlPath := "/documentation/text-formatting/italic" + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.endpoint, urlPath)) + if err != nil { + return nil, err + } + return req, nil +} diff --git a/packages/typespec-go/test/http-specs/documentationgroup/zz_models.go b/packages/typespec-go/test/http-specs/documentationgroup/zz_models.go new file mode 100644 index 000000000..0dee6934e --- /dev/null +++ b/packages/typespec-go/test/http-specs/documentationgroup/zz_models.go @@ -0,0 +1,34 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) Go Code Generator. DO NOT EDIT. + +package documentationgroup + +// BulletPointsModel - This tests: +// - Simple bullet point. This bullet point is going to be very long to test how text wrapping is handled in bullet points +// within documentation comments. It should properly indent the wrapped lines. +// - Another bullet point with **bold text**. This bullet point is also intentionally long to see how the formatting is preserved +// when the text wraps onto multiple lines in the generated documentation. +// - Third bullet point with *italic text*. Similar to the previous points, this one is extended to ensure that the wrapping +// and formatting are correctly applied in the output. +// - Complex bullet point with **bold** and *italic* combined. This bullet point combines both bold and italic formatting +// and is long enough to test the wrapping behavior in such cases. +// - **Bold bullet point**: A bullet point that is entirely bolded. This point is also made lengthy to observe how the bold +// formatting is maintained across wrapped lines. +// - *Italic bullet point*: A bullet point that is entirely italicized. This final point is extended to verify that italic +// formatting is correctly applied even when the text spans multiple lines. +type BulletPointsModel struct { + // REQUIRED; This property uses an enum with bullet point documentation. The enum documentation includes various formatting + // styles to test rendering. The styles are: + // - Simple bullet point. This bullet point is going to be very long to test how text wrapping is handled in bullet points + // within documentation comments. It should properly indent the wrapped lines. + // - Bullet point with **bold text**. This bullet point is also intentionally long to see how the formatting is preserved + // when the text wraps onto multiple + // - Bullet point with *italic text*. Similar to the previous points, this one is extended to ensure that the wrapping and + // formatting are correctly applied in the output. + // - Complex bullet point with **bold** and *italic* combined. This bullet point combines both bold and italic formatting + // and is long enough to test the wrapping behavior in such cases. + // - **Bold bullet point** + // - *Italic bullet point* + Prop *BulletPointsEnum +} diff --git a/packages/typespec-go/test/http-specs/documentationgroup/zz_models_serde.go b/packages/typespec-go/test/http-specs/documentationgroup/zz_models_serde.go new file mode 100644 index 000000000..9fdee7265 --- /dev/null +++ b/packages/typespec-go/test/http-specs/documentationgroup/zz_models_serde.go @@ -0,0 +1,59 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) Go Code Generator. DO NOT EDIT. + +package documentationgroup + +import ( + "encoding/json" + "fmt" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "reflect" +) + +// MarshalJSON implements the json.Marshaller interface for type BulletPointsModel. +func (b BulletPointsModel) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "prop", b.Prop) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type BulletPointsModel. +func (b *BulletPointsModel) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", b, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "prop": + err = unpopulate(val, "Prop", &b.Prop) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", b, err) + } + } + return nil +} + +func populate(m map[string]any, k string, v any) { + if v == nil { + return + } else if azcore.IsNullValue(v) { + m[k] = nil + } else if !reflect.ValueOf(v).IsNil() { + m[k] = v + } +} + +func unpopulate(data json.RawMessage, fn string, v any) error { + if data == nil || string(data) == "null" { + return nil + } + if err := json.Unmarshal(data, v); err != nil { + return fmt.Errorf("struct field %s: %v", fn, err) + } + return nil +} diff --git a/packages/typespec-go/test/http-specs/documentationgroup/zz_options.go b/packages/typespec-go/test/http-specs/documentationgroup/zz_options.go new file mode 100644 index 000000000..46580c641 --- /dev/null +++ b/packages/typespec-go/test/http-specs/documentationgroup/zz_options.go @@ -0,0 +1,40 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) Go Code Generator. DO NOT EDIT. + +package documentationgroup + +// DocumentationListsClientBulletPointsModelOptions contains the optional parameters for the DocumentationListsClient.BulletPointsModel +// method. +type DocumentationListsClientBulletPointsModelOptions struct { + // placeholder for future optional parameters +} + +// DocumentationListsClientBulletPointsOpOptions contains the optional parameters for the DocumentationListsClient.BulletPointsOp +// method. +type DocumentationListsClientBulletPointsOpOptions struct { + // placeholder for future optional parameters +} + +// DocumentationListsClientNumberedOptions contains the optional parameters for the DocumentationListsClient.Numbered method. +type DocumentationListsClientNumberedOptions struct { + // placeholder for future optional parameters +} + +// DocumentationTextFormattingClientBoldTextOptions contains the optional parameters for the DocumentationTextFormattingClient.BoldText +// method. +type DocumentationTextFormattingClientBoldTextOptions struct { + // placeholder for future optional parameters +} + +// DocumentationTextFormattingClientCombinedFormattingOptions contains the optional parameters for the DocumentationTextFormattingClient.CombinedFormatting +// method. +type DocumentationTextFormattingClientCombinedFormattingOptions struct { + // placeholder for future optional parameters +} + +// DocumentationTextFormattingClientItalicTextOptions contains the optional parameters for the DocumentationTextFormattingClient.ItalicText +// method. +type DocumentationTextFormattingClientItalicTextOptions struct { + // placeholder for future optional parameters +} diff --git a/packages/typespec-go/test/http-specs/documentationgroup/zz_responses.go b/packages/typespec-go/test/http-specs/documentationgroup/zz_responses.go new file mode 100644 index 000000000..0d698a581 --- /dev/null +++ b/packages/typespec-go/test/http-specs/documentationgroup/zz_responses.go @@ -0,0 +1,35 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) Go Code Generator. DO NOT EDIT. + +package documentationgroup + +// DocumentationListsClientBulletPointsModelResponse contains the response from method DocumentationListsClient.BulletPointsModel. +type DocumentationListsClientBulletPointsModelResponse struct { + // placeholder for future response values +} + +// DocumentationListsClientBulletPointsOpResponse contains the response from method DocumentationListsClient.BulletPointsOp. +type DocumentationListsClientBulletPointsOpResponse struct { + // placeholder for future response values +} + +// DocumentationListsClientNumberedResponse contains the response from method DocumentationListsClient.Numbered. +type DocumentationListsClientNumberedResponse struct { + // placeholder for future response values +} + +// DocumentationTextFormattingClientBoldTextResponse contains the response from method DocumentationTextFormattingClient.BoldText. +type DocumentationTextFormattingClientBoldTextResponse struct { + // placeholder for future response values +} + +// DocumentationTextFormattingClientCombinedFormattingResponse contains the response from method DocumentationTextFormattingClient.CombinedFormatting. +type DocumentationTextFormattingClientCombinedFormattingResponse struct { + // placeholder for future response values +} + +// DocumentationTextFormattingClientItalicTextResponse contains the response from method DocumentationTextFormattingClient.ItalicText. +type DocumentationTextFormattingClientItalicTextResponse struct { + // placeholder for future response values +} diff --git a/packages/typespec-go/test/http-specs/documentationgroup/zz_version.go b/packages/typespec-go/test/http-specs/documentationgroup/zz_version.go new file mode 100644 index 000000000..bf8a2484e --- /dev/null +++ b/packages/typespec-go/test/http-specs/documentationgroup/zz_version.go @@ -0,0 +1,10 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) Go Code Generator. + +package documentationgroup + +const ( + moduleName = "documentationgroup" + moduleVersion = "v0.1.0" +)