MCPcopy Create free account
hub / github.com/github/gh-aw / TestExtractSchemaExamples

Function TestExtractSchemaExamples

pkg/parser/schema_suggestions_test.go:778–832  ·  view source on GitHub ↗

TestExtractSchemaExamples tests that examples are extracted from the schema for a given JSON path.

(t *testing.T)

Source from the content-addressed store, hash-verified

776
777// TestExtractSchemaExamples tests that examples are extracted from the schema for a given JSON path.
778func TestExtractSchemaExamples(t *testing.T) {
779 schemaJSON := `{
780 "type": "object",
781 "properties": {
782 "timeout-minutes": {
783 "type": "integer",
784 "minimum": 1,
785 "examples": [5, 10, 30]
786 },
787 "name": {
788 "type": "string",
789 "examples": ["My Workflow"]
790 },
791 "no-examples": {
792 "type": "integer"
793 }
794 }
795 }`
796 var schemaDoc any
797 require.NoError(t, json.Unmarshal([]byte(schemaJSON), &schemaDoc), "Failed to parse schema JSON")
798
799 tests := []struct {
800 name string
801 jsonPath string
802 want []string
803 }{
804 {
805 name: "integer field with examples",
806 jsonPath: "/timeout-minutes",
807 want: []string{"5", "10", "30"},
808 },
809 {
810 name: "string field with examples",
811 jsonPath: "/name",
812 want: []string{"My Workflow"},
813 },
814 {
815 name: "field without examples",
816 jsonPath: "/no-examples",
817 want: nil,
818 },
819 {
820 name: "non-existent path",
821 jsonPath: "/does-not-exist",
822 want: nil,
823 },
824 }
825
826 for _, tt := range tests {
827 t.Run(tt.name, func(t *testing.T) {
828 got := extractSchemaExamples(schemaDoc, tt.jsonPath)
829 assert.Equal(t, tt.want, got, "extractSchemaExamples(%q) should return expected examples", tt.jsonPath)
830 })
831 }
832}
833
834// TestGenerateSchemaBasedSuggestions_RangeConstraintExamples tests that examples are surfaced
835// for minimum/maximum constraint violations.

Callers

nothing calls this directly

Calls 2

extractSchemaExamplesFunction · 0.85
RunMethod · 0.45

Tested by

no test coverage detected